我在我的应用程序中使用ASP.NET身份时出错.
不支持每种类型的多个对象集.对象集"Identity Users"和"Users"都可以包含"Recommendation Platform.Models.ApplicationUser"类型的实例.
我在StackOverflow中看到了一些关于这个错误的问题.全部表示两个DbSet相同类型的对象.但在我看来DbContext有不一样的类型DbSets.FindAsync()在登录期间抛出方法的异常.
if (ModelState.IsValid)
var user = await UserManager.FindAsync(model.UserName, model.Password);
if (user != null && user.IsConfirmed)
{
Run Code Online (Sandbox Code Playgroud)
问题是我没有两个DbSets相同的类型.我的上下文看起来像这样:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
public System.Data.Entity.DbSet<RecommendationPlatform.Models.ApplicationUser> IdentityUsers { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
和
public class RecContext : DbContext
{
public RecContext()
: base("RecConnection")
{
Database.SetInitializer<RecContext>(new DropCreateDatabaseIfModelChanges<RecContext>());
}
public DbSet<Recommendation> Recommendations { get; set; }
public DbSet<Geolocation> Geolocations { get; set; } …Run Code Online (Sandbox Code Playgroud) 在使用EF 6的VS 2013 RTM,MVC 5项目中,我尝试使用基于ApplicationUser的控制器(默认使用个人帐户身份验证)来构建控制器.双方ApplicationUser并IdentityUser映射到用户表.该向导打开上下文文件以进行编辑,并尝试为ApplicationUser(ApplicationUsers)添加新的数据库集,然后失败并显示以下错误:
Unable to retrieve metadata for ApplicationUser. Multiple object sets per type are not supported. The object sets ApplicationUsers and Users can both contain instances of type ApplicationUser
该解决方案没有任何参考或实例ApplicationUsers.
这是一个已知的问题?脚手架可以使用命令行和选项(来自PMC)运行吗?注意:如果我指定一个引用ApplicationUser的模型,脚手架还会向上下文类添加一个额外的数据库集(如果删除它并在生成控制器中修复引用,则应用程序可以正常工作).
对象集IdentityUsers'和用户都可以包含net类型的实例
但是我试图创建一个多对多的关系,比如这个教程显示了get-started-with-ef-using-mvc
但我得到了这个错误=>
Multiple object sets per type are not supported. The object sets 'IdentityUsers' and 'Users' can both contain instances of type 'bugs_b_gone.Models.ApplicationUser'.
我在项目类中有一个属性,因此创建项目的用户是管理员但是现在管理员必须创建用户并将其分配给项目
public class Project
{
[Key]
public int ProjectID { get; set; }
//public int AdminID { get; set; }
[Required]
[StringLength(50, ErrorMessage = "Title cannot be longer than 50 characters.")]
[Column("Title")]
[Display(Name = "Title")]
public string Title { get; set; }
[Required]
public string Description { get; set; }
//public int MemberID { …Run Code Online (Sandbox Code Playgroud)