如果您使用过ASP.NET MVC 4,您会注意到Internet应用程序的默认设置是使用SimpleMembership提供程序,这很好,功能正常。但是问题出现在默认数据库生成上,他们为UserProfile定义了一个POCO,如下所示:
[Table("UserProfile")]
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
}
.. which is then generated like this:
using (var context = new UsersContext())
{
if (!context.Database.Exists())
{
// Create the SimpleMembership database without Entity Framework migration schema
((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
}
}
这段代码运行良好,数据库生成成功,且没有问题。但是,如果我将POCO更改为以下内容并删除数据库:
[Table("UserProfile")]
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string EmailAddress { get; set; }
public string FirstName { get; set; }
public string Surname { get; set; }
public string Country { get; set; }
public string CompanyName { get; set; }
}
只有前两列生成,UserId
和 EmailAddress
。从代码上看(登录/注册方面),一切都正常,但显然我的其他用户数据都没有存储。
我错过了什么吗?它应该基于整个 UserProfile
对象生成数据库,是吗?
UserId
和EmailAddress
(或者无论我将它们重命名为什么)都很好地存在着。 - Rudi Visser