【发布时间】:2015-05-12 15:17:24
【问题描述】:
我遵循以下内容并使用ApplicationUser 而不是自己创建。 ApplicationUser 来自默认的 MVC 5 应用程序:
这是我的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<Field> Fields { get; set; }
}
这是我的Field 代码:
public class Field
{
[Key]
public int FieldID { get; set; }
// [ForeignKey( "Id" )] // Not sure if i needed this but neither worked
public virtual ApplicationUser CreatedBy { get; set; }
...
但是当我运行PM> Add-Migration AddedCreatedByToFields时出现以下错误:
One or more validation errors were detected during model generation:
FieldApplication.Domain.Concrete.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType.
FieldApplication.Domain.Concrete.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType.
IdentityUserLogins: EntityType: EntitySet 'IdentityUserLogins' is based on type 'IdentityUserLogin' that has no keys defined.
IdentityUserRoles: EntityType: EntitySet 'IdentityUserRoles' is based on type 'IdentityUserRole' that has no keys defined.
任何想法我做错了什么?
旁注
我将我的 ApplicationUser 代码移到了一个名为 Domains 的单独项目中。我包含了 Identity Nuget 包以获取其中的命名空间...
【问题讨论】:
-
没有人回答是因为代码似乎正确吗?如果是这样,那将帮助我找到问题:)
标签: c# asp.net asp.net-mvc-5 asp.net-identity-2