【问题标题】:Asp.net MVC + Membership + Code-First + Existing DatabaseAsp.net MVC + 成员资格 + 代码优先 + 现有数据库
【发布时间】:2012-09-16 17:36:41
【问题描述】:

经过大量研究和尝试,我失败了,情况如下:

技术

  • Asp.Net MVC4
  • 实体框架代码优先
  • 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 节课

我想要的只是:

使用 Asp.Net Membership 系统,并将其插入我的课程。我有一个名为 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 Membership 和 AccountController 注册的 Asp.Net 用户联系起来

我在 stackoverflow、codeplex 等中进行搜索,但我没有找到解决方案,或者我可能不明白。

我希望有人在现实世界的应用中实现了这一点:)

ps:我正在开发一个“约会”网站

【问题讨论】:

  • 看看SimpleMembership提供者,它带有网络矩阵。
  • 我已经测试了 SimpleMemebership,但我尝试在我的域类和 UserProfile 之间建立关系没有成功。关于如何将 simplemembership 与其他域类集成的文档并不多

标签: sql asp.net-mvc entity-framework asp.net-membership


【解决方案1】:

MVC 4 中的 AccountController 已经依赖 SimepleMembership 和其他 WebMatrix 位来支持 OAuth 和本地帐户的成员资格。

我的建议是首先删除在您的 MVC 4 项目的 AccountModel.cs 中定义的 DbContext 派生类,然后用您自己的替换它(编译器错误会告诉您删除类后必须更改的内容) .

我还将从项目中删除 SimpleMembershipInitializerAttribute,并确保改为在 Application_Start 期间执行初始化任务。过滤器有一些细微的缺陷。当我有机会发布有关此内容时,我将使用 URL 进行更新。

【讨论】:

  • 这正是我在阅读您的答案之前使用的方式 :) 完美!
  • 是的,SimpleMembership 的工作方式与您期望的会员提供商的工作方式不同,而且它失败的地方之一是配置。你必须手动加载那个,我相信:(
猜你喜欢
  • 2011-07-24
  • 1970-01-01
  • 1970-01-01
  • 2016-08-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-27
  • 1970-01-01
相关资源
最近更新 更多