public ActionResult Restaurants()
{
var restaurants = _context.ApplicationUsers.ToList();
return View(restaurants);
}
I want to extract the the information of registerd users from ASP.NET MVC and list it. But when I executed above code, I get error message of:
我想从ASP中提取registerd用户的信息。列出MVC。但是当我执行上述代码时,我得到的错误信息是:
Multiple object sets per type are not supported. The object sets 'ApplicationUsers' and 'Users' can both contain instances of type 'ESportsScreening.Models.ApplicationUser'.
不支持每个类型有多个对象集。对象集“ApplicationUsers”和“Users”都可以包含“esportal . models . model . applicationuser”类型的实例。
How can I list the informations of Registered users in ASP.NET MVC 5?
如何在ASP中列出注册用户的信息。净MVC 5 ?
2 个解决方案
#1
2
ASP.NET does not allow you to have 2 DbSet<T>
's in the same context with the same entity type. The most likely cause of this error is initializing your DbContext
like the following:
ASP。NET不允许在相同的上下文中有2个DbSet
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public DbSet<ApplicationUser> ApplicationUsers { get; set; }
}
In the above code, ApplicationDbContext
already contains a DbSet
of type ApplicationUser
inherited from IdentityDbContext<ApplicationUser>
(which you can access through _context.Users
). By manually adding a second DbSet<ApplicationUser>
, we are creating 2 sets with the same entity type. Delete the manual DbSet
property, and use the inherited Users
set instead.
在上面的代码中,ApplicationDbContext已经包含一组从IdentityDbContext
#2
0
The error indicates that you have 2 objectsets of same type ESportsScreening.Models.ApplicationUser. You should remove one of them to resolve this error. You should only have one object set per type and you do not need more.
这个错误表明您有两个相同类型esportsscreen. model . applicationuser的objectset。您应该删除其中一个以解决此错误。每个类型应该只有一个对象集,不需要更多。
To help you find out how can you find registered users you need to provide some information about what are you considering as registered users. I guess all the users you have in your database are registered users in which case the following line of code is enough:
为了帮助您了解如何找到注册用户,您需要提供一些关于您考虑的注册用户的信息。我想您数据库中的所有用户都是注册用户,在这种情况下,下面的代码就足够了:
var restaurants = _context.ApplicationUsers.ToList();
var = _context.ApplicationUsers.ToList餐馆();
In case you need to filter the users, you can use the Where extension method as follows:
如果需要筛选用户,可以使用Where扩展方法如下:
var restaurants = _context.ApplicationUsers.Where( x=> yourconditionhere ).ToList();
var = _context.ApplicationUsers餐馆。在(x = > yourconditionhere).ToList();
#1
2
ASP.NET does not allow you to have 2 DbSet<T>
's in the same context with the same entity type. The most likely cause of this error is initializing your DbContext
like the following:
ASP。NET不允许在相同的上下文中有2个DbSet
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public DbSet<ApplicationUser> ApplicationUsers { get; set; }
}
In the above code, ApplicationDbContext
already contains a DbSet
of type ApplicationUser
inherited from IdentityDbContext<ApplicationUser>
(which you can access through _context.Users
). By manually adding a second DbSet<ApplicationUser>
, we are creating 2 sets with the same entity type. Delete the manual DbSet
property, and use the inherited Users
set instead.
在上面的代码中,ApplicationDbContext已经包含一组从IdentityDbContext
#2
0
The error indicates that you have 2 objectsets of same type ESportsScreening.Models.ApplicationUser. You should remove one of them to resolve this error. You should only have one object set per type and you do not need more.
这个错误表明您有两个相同类型esportsscreen. model . applicationuser的objectset。您应该删除其中一个以解决此错误。每个类型应该只有一个对象集,不需要更多。
To help you find out how can you find registered users you need to provide some information about what are you considering as registered users. I guess all the users you have in your database are registered users in which case the following line of code is enough:
为了帮助您了解如何找到注册用户,您需要提供一些关于您考虑的注册用户的信息。我想您数据库中的所有用户都是注册用户,在这种情况下,下面的代码就足够了:
var restaurants = _context.ApplicationUsers.ToList();
var = _context.ApplicationUsers.ToList餐馆();
In case you need to filter the users, you can use the Where extension method as follows:
如果需要筛选用户,可以使用Where扩展方法如下:
var restaurants = _context.ApplicationUsers.Where( x=> yourconditionhere ).ToList();
var = _context.ApplicationUsers餐馆。在(x = > yourconditionhere).ToList();