经过大量研究和尝试失败后,情况如下:
技术
- Asp.Net MVC4
- Entity Framework 代码优先
- SQL Server 2008
我使用 Code First 来创建我的域类,例如:
public class Country{
public int IdCountry {get;set;}
public int NameCountry {get;set;}
}
public class Sex{
public int IdSex {get;set;}
public int NameSex{get;set;}
}
等等...我有大约 20 个类(class)
我想要的是:
使用 Asp.Net 成员(member)系统,并将其插入我的类(class)。我有一个名为 UserProfile 的域类
public class UserProfile{
public int IdUserProfile {get;set;}
public virtual Sex sex {get;set;}
public virtual Country country {get;set;}
public virtual ICollection<Photos> photos {get;set;}
etc...
}
我希望能够将所有这些与通过 Asp.Net 成员(member)资格和 AccountController 注册的 Asp.Net 用户连接起来
我在 stackoverflow、codeplex 等中搜索,但没有找到解决方案,或者也许我不明白。
我希望有人在现实世界的应用中实现了这一点:)
ps:我正在开发一个“约会”网站
最佳答案
MVC 4 中的 AccountController 已经依赖 SimepleMembership 和其他 WebMatrix 位来支持 OAuth 和本地帐户的成员资格。
我的建议是首先删除 MVC 4 项目的 AccountModel.cs 中定义的 DbContext 派生类,并将其替换为您自己的类(编译器错误会告诉您删除该类后必须更改哪些内容) 。
我还将从项目中删除 SimpleMembershipInitializerAttribute 并确保在 Application_Start 期间执行初始化任务。该过滤器有一些细微的缺陷。当我有机会发布有关此内容时,我将使用 URL 更新此内容。
关于sql - Asp.net MVC + 成员资格 + 代码优先 + 现有数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12449126/