Entity Framework 6 Creating Two table from the same entity object

asp.net c# code-first ef-code-first entity-framework-6

Question

If it's feasible to build two table instances from a single defined entity object type, that is what I was wondering.

Example:

public class EntityA()
{
    public String name {get; set;}
    public String value {get; set;}
}

public class MyDbConext : DbContext
{
    public DbSet<EntityA> instance1{ get; set; }
    public DbSet<EntityA> instance2{ get; set; }
}

I'm attempting to build two Entity A instances with distinct table names. Does the Code First Entity Framework allow for that? To simply create another instance of EntityA, one must construct a new class that extends EntityA, which sounds laborious to me.

Desired Results:

  • "Instance1 Table" is made from the EntityA class.
  • "Instance2 Table" is made from the EntityA class.

An exception will be thrown by the code in the DBConext.

Any suggestions are welcome. Thanks, D

1
6
8/11/2015 7:02:51 AM

Accepted Answer

You can't have more than oneDbSet directing to the same class in oneDbContext Your choices are:

  • Adding additional attributes to an existing class
  • Inheritance
  • using variousDBContext s
6
8/11/2015 7:29:07 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow