我有一个带有 Person 对象的类库,它还继承了其他两种类型。我最初使用它来扩展一个人的 aspnetdb 属性,但后来遇到了 SimpleMembership 安全性,并且一直试图让它工作。
{
public abstract class Person
{
[Key]
public int Id { get; set; }
/// <summary>
/// eg. AB123
/// </summary>
public string Uid { get; set; }
public bool? IsRepresrentative { get; set; }
[Display(Name = "First Name")]
public string FirstName { get; set; }
[Display(Name = "Preferred First Name")]
public string FirstNamePreferred { get; set; }
[Display(Name = "Last Name")]
public string LastName { get; set; }
[Display(Name = "Full Name")]
public string FullName { get; set; }
public string Email { get; set; }
public string EmailAdditional { get; set; }
public string Telephone { get; set; }
[Display(Name = "Job Title")]
public string JobTitle { get; set; }
public string PersonalPage { get; set; }
public string ServiceArea { get; set; }
//Profile items
public int? PrefNewsItemsToShow { get; set; }
public override string ToString()
{
return FullName ??
string.Format("{0} {1}", string.IsNullOrEmpty(FirstNamePreferred) ? FirstName : FirstNamePreferred, LastName);
}
}
public class ProviderUser : Person
{
public ICollection<Provider> Providers { get; set; }
}
public class SchoolUser : Person
{
public ICollection<School> Schools { get; set; }
}
}
我在 InitializeSimpleMembershipAttribute.cs 中有以下设置
WebSecurity.InitializeDatabaseConnection("MyCommonContext", "People", "Id", "Uid", autoCreateTables: true);
如果我没有将它放在带有鉴别器的桌子上,这似乎可行。但我认为上面的想法是这样的,这样您就可以使用还包含其他数据的表。
有两种看待我的问题的方式。1. 当它尝试从 AccountController 创建用户时,我得到以下设置:
Cannot insert the value NULL into column 'Discriminator', table 'dbo.People'; column does not allow nulls. INSERT fails.
我该如何解决?
- 或者另一种看待它的方式,我怎样才能以不同/更好的方式做我想做的事?