我想知道是否可以从一个已定义的实体对象类创建两个表实例。
例:
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; } }我要做的是创建两个具有不同表名的实体A实例。 这可能与代码第一实体框架? 我觉得只需要创建另一个扩展实体EntityA的类来创建同一个实体的另一个实例似乎很乏味。
期望的输出:
从EntityA类创建“Instance1_Table” 从EntityA类创建“Instance2_Table”DBConext中的代码将引发异常。
任何建议表示赞赏,谢谢,D
I was wondering if it's possible to create two table instance from one defined entity object class.
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; } }What i'm trying to do is create two instances of Entity A with different table names. Is that possible with code first entity framework? I feel like it's seems tedious to have to just create another class that extends entity EntityA to just create another instance of the same entity.
Desired Output:
Creation of "Instance1_Table" from EntityA class Creation of "Instance2_Table" from EntityA classThe code in the DBConext will throw an exception.
Any advice appreciated, Thanks, D
最满意答案
您不能让多个DbSet指向一个DbContext的同一个类。 你的选择是:
创建具有相同属性的新类 遗产 使用不同的DBContextYou cannot have multiple DbSet pointing to the same class in one DbContext. Your options are:
Creating new class with same properties Inheritance Using different DBContexts更多推荐
发布评论