我有一个由entityframework为我的用户生成的POCO类:
public partial class AppUser : BaseEntity
{
public int User_Id { get; set; }
public string SpecialProperty { get; set; }
}
我有一个花哨的身份验证提供程序项目,它实现了AspNet Identity,并且有一个继承自microsoft提供的IdentityUser的MyIdentityUser类。
public class MyIdentityUser : IdentityUser<int, MyIdentityUserLogin, MyIdentityUserRole, MyIdentityUserClaim>
{
.... (needs the properties of appuser around here) ...
.... (need the properties of IdentityUser around here too) ...
}
现在因为我想在多个项目中使用我的花哨的身份验证提供程序,我需要传入&#34;实际类型&#34;数据库存储中的对象 - 以便可以填充非可空字段等。
类MyIdentityUser需要POCO类的属性,以便从db中检索这些属性,并正确创建新记录,并且需要IdentityUser的属性才能使用microsoft的aspnet身份实现。
我希望能够写下面的语句,以便我可以传入要使用的类型:
IdentityProvider<AppUser> provider = new IdentityProvider<AppUser>();
但我的问题是 - 我的AppUser类继承自BaseEntity,而MyIdentityUser必须继承自IdentityUser,因此无法扩展AppUser。
如果没有:
,我该如何解决这个问题?1)将auth提供程序与EF类型紧密耦合?
2)将所有POCO属性重写为项目中的硬编码接口,并继承该属性(属性首先从数据库驱动)
我已经尝试将POCO类添加为MyIdentityUser的属性,但是aspnet身份的实体框架部分不起作用,因为您可能不使用泛型。
我被卡住了,我想我在概念层面上遗漏了一些东西。很高兴根据需要提供更多细节..
答案 0 :(得分:1)
我在一个类似问题的项目中使用了nhibernate,而我最终在我的模型中实现了IUser。这里Id在BaseModel
中public class ModelClass : BaseModel, IUser
{
public string Name { get; set; }
string IUset<string>Id { get { return this.Id.ToString(); } }
}
希望这有帮助。