Я застрял в нечетной проблеме.Несколько наборов объектов для каждого типа не поддерживаются. Наборы объектов «ApplicationUsers» и «Users» могут содержать экземпляры типа ApplicationUser
Я изучаю MVC 5 и почти все создано встроенным шаблоном. я только добавил класс История
public class History
{
[Key]
public DateTime Date { get; set; }
public virtual ApplicationUser User { get; set; }
public string ItemName { get; set; }
}
А внутри встроенного ApplicationUser:
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
public virtual ICollection<History> Histories { get; set; }
}
Вот сообщение об ошибке:
Multiple object sets per type are not supported. The object sets 'ApplicationUsers' and 'Users' can both contain instances of type 'MyOnlineShopping.Models.ApplicationUser'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Multiple object sets per type are not supported. The object sets 'ApplicationUsers' and 'Users' can both contain instances of type 'MyOnlineShopping.Models.ApplicationUser'.
Source Error:
Line 124: {
Line 125: var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };
Line 126: IdentityResult result = await UserManager.CreateAsync(user, model.Password);
Line 127: if (result.Succeeded)
Line 128: {
Source File: f:\Workplace\MyOnlineShopping\MyOnlineShopping\Controllers\AccountController.cs Line: 126
Я столкнулся с той же проблемой. В моем случае все работало нормально, пока я не добавил действие моему контроллеру, а затем добавил представление к действию. Я удалил действие и представление, но все равно получаю сообщение об ошибке. (Это единственные две вещи, которые я знаю о добавлении) –
привет @JohnS Я думаю, что нашел «поверхностный ответ» для этого. Я обнаружил, что кажется, что EntityFramework автоматически добавила коллекцию IdentityUser в ApplicationUser. Я удалил это, проблема исчезла. Надеюсь, это поможет вам. – Franva