我有两个相关的类,它们共享一个公共接口,并且都存储在同一个底层数据库表中。然而,Entity Framework生成了一个通用类,而我实际上需要这两个不同的类。我该如何解决这个问题?是最好使用基类而不是接口?如何更改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 { get; set; }
}