我有两个相关的类,它们共享一个公共接口,并且都存储在同一个底层数据库表中.但是,实体框架生成一个公共类,我真的需要两个不同的类.我该如何解决这个问题?最好使用基类而不是接口吗?如何更改EF模型以提供映射到一个表的两个类?
编辑: AccountType属性确定类的类型; 用户或组.
一些简单的代码:
public interface IAccount
{
string Name { get; set; }
AccountType AccountType { get; set; }
}
public class GroupAccount : IAccount
{
public string Name { get; set; }
public GroupType GroupType { get; set; }
public AccountType AccountType { get; set; }
}
public class UserAccount : IAccount
{
public string Username { get; set; }
public string Password { get; set; }
public string Name { get; set; }
public AccountType AccountType …
Run Code Online (Sandbox Code Playgroud)