Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://msdn.microsoft.com/en-us/library/gg197525%28v=vs.103%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/gg197525%28v=vs.103%29.aspx</a></p> <p>I'm not saying it cannot be done, but these examples don't show such a thing being done.</p> <p>If you use Fluent-API conventions, however, it's quite simple.</p> <p>Your POCO definitions:</p> <pre><code>public class BaseClass { public int Id {get; set;} } public class DerivedClass : BaseClass { public string Data {get; set;} } </code></pre> <p>Configuring the mappings to the DB:</p> <pre><code>public class BaseConfiguration : EntityTypeConfiguration&lt;BaseClass&gt; { public BaseConfiguration() { HasKey(k =&gt; k.Id); Property(p =&gt; p.Id).HasColumnName("Id").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity).IsRequired(); } } public class DerivedConfiguration : BaseConfiguration { public DerivedConfiguration() { Property(p =&gt; p.Id).HasColumnName("BaseClassId"); } } </code></pre> <p>putting it all together</p> <pre><code>public class MyContext : DbContext { public MyContext(string connectionString) : base(connectionString) { Database.SetInitializer&lt;MyContext&gt;(null); } public DbSet&lt;BaseClass&gt; Bases { get; set; } public DbSet&lt;DerivedClass&gt; Deriveds { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Configurations.Add(new BaseConfiguration()); modelBuilder.Configurations.Add(new DerivedConfiguration()); } } </code></pre> <p>So you instantiate a MyContext passing in your connection string and the configurations tell EF how to relate to the tables.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload