C# 实体框架无法识别自定义标识属性
我设置了如下应用程序用户类型:C# 实体框架无法识别自定义标识属性,c#,entity-framework,asp.net-web-api,C#,Entity Framework,Asp.net Web Api,我设置了如下应用程序用户类型: public class BusinessAccount : IdentityUser { [Required] [MaxLength(100)] public string RepFirstName { get; set; } [Required] [MaxLength(100)] public string RepLastName { get; set; } [Required] public s
public class BusinessAccount : IdentityUser
{
[Required]
[MaxLength(100)]
public string RepFirstName { get; set; }
[Required]
[MaxLength(100)]
public string RepLastName { get; set; }
[Required]
public string Title { get; set; }
[Required]
public DateTime JoinDate { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<BusinessAccount> manager, string authenticationType)
{
var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);
// Add custom user claims here
return userIdentity;
}
}
初始迁移。。。。看不到定制道具强>
公共部分类InitialCreate:DbMigration
{
公共覆盖作废()
{
创建表(
“dbo.AspNetRoles”,
c=>新的
{
Id=c.String(可空:false,maxLength:128),
Name=c.String(可空:false,最大长度:256),
})
.PrimaryKey(t=>t.Id)
.Index(t=>t.Name,惟一:true,Name:“RoleNameIndex”)
}你也实现了UserStore吗?@MaximilianoRios根据本教程:在DB中创建属性不需要这一步。注意,他直到之后才实现UserStore。我也尝试过实现它,但它并没有解决问题:\I确实理解,只是我看不到(通常)一个没有添加UserStore的实现。不管怎样,你能指出你正在使用的是什么版本的吗?框架,如果,等等。这样我可以看一下。谢谢。我不确定你说的如果是什么意思,但我刚刚用版本更新了帖子。迁移从IdentityDbContext获取t类型来构建对象。只是为了确认我创建了它d迁移,添加对象时效果很好。你能从InitialCreate类发布你的CreateTable代码吗?我的工作很好。你也实现了UserStore吗?@MaximilianoRios根据本教程:在DB中创建属性不需要这一步。注意,他直到之后才实现UserStore。我还试图实现它,但没有解决问题:\n我确实理解,只是我看不到(通常)一个没有添加UserStore的实现。不管怎样,你能指出你正在使用的是什么版本的吗?框架,如果,等等。这样我可以看一下。谢谢。我不确定你说的如果是什么意思,但我刚刚用版本更新了帖子。迁移从IdentityDbContext获取t类型来构建对象。只是为了确认我创建了它d迁移,添加对象效果很好。你能从InitialCreate类发布你的CreateTable代码吗?我的很好
public class AleHubDbContext :IdentityDbContext<BusinessAccount>
{
public AleHubDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
Configuration.ProxyCreationEnabled = false;
Configuration.LazyLoadingEnabled = false;
}
public static AleHubDbContext Create()
{
return new AleHubDbContext();
}
}
Id Versions ProjectName
-- -------- -----------
EntityFramework {6.1.3} AleHub.API
Microsoft.AspNet.Identity.Core {2.2.1} AleHub.API
Microsoft.AspNet.Identity.Entity... {2.2.1} AleHub.API
Microsoft.AspNet.Identity.Owin {2.2.1} AleHub.API
Microsoft.AspNet.WebApi {5.2.3} AleHub.API
Microsoft.AspNet.WebApi.Client {5.2.3} AleHub.API
Microsoft.AspNet.WebApi.Core {5.2.3} AleHub.API
Microsoft.AspNet.WebApi.Owin {5.2.3} AleHub.API
Microsoft.AspNet.WebApi.OwinSelf... {5.2.3} AleHub.API
Microsoft.AspNet.WebApi.WebHost {5.2.3} AleHub.API
Microsoft.CodeDom.Providers.DotN... {1.0.0} AleHub.API
Microsoft.Net.Compilers {1.0.0} AleHub.API
Microsoft.Owin {3.0.1} AleHub.API
Microsoft.Owin.Host.HttpListener {2.0.2} AleHub.API
Microsoft.Owin.Hosting {2.0.2} AleHub.API
Microsoft.Owin.Security {3.0.1} AleHub.API
Microsoft.Owin.Security.Cookies {3.0.1} AleHub.API
Microsoft.Owin.Security.OAuth {3.0.1} AleHub.API
Newtonsoft.Json {6.0.4} AleHub.API
Owin {1.0} AleHub.API
Antlr {3.4.1.9004}
CreateTable(
"dbo.AspNetUserRoles",
c => new
{
UserId = c.String(nullable: false, maxLength: 128),
RoleId = c.String(nullable: false, maxLength: 128),
})
.PrimaryKey(t => new { t.UserId, t.RoleId })
.ForeignKey("dbo.AspNetRoles", t => t.RoleId, cascadeDelete: true)
.ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true)
.Index(t => t.UserId)
.Index(t => t.RoleId);
CreateTable(
"dbo.AspNetUsers",
c => new
{
Id = c.String(nullable: false, maxLength: 128),
Email = c.String(maxLength: 256),
EmailConfirmed = c.Boolean(nullable: false),
PasswordHash = c.String(),
SecurityStamp = c.String(),
PhoneNumber = c.String(),
PhoneNumberConfirmed = c.Boolean(nullable: false),
TwoFactorEnabled = c.Boolean(nullable: false),
LockoutEndDateUtc = c.DateTime(),
LockoutEnabled = c.Boolean(nullable: false),
AccessFailedCount = c.Int(nullable: false),
UserName = c.String(nullable: false, maxLength: 256),
})
.PrimaryKey(t => t.Id)
.Index(t => t.UserName, unique: true, name: "UserNameIndex");
CreateTable(
"dbo.AspNetUserClaims",
c => new
{
Id = c.Int(nullable: false, identity: true),
UserId = c.String(nullable: false, maxLength: 128),
ClaimType = c.String(),
ClaimValue = c.String(),
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true)
.Index(t => t.UserId);
CreateTable(
"dbo.AspNetUserLogins",
c => new
{
LoginProvider = c.String(nullable: false, maxLength: 128),
ProviderKey = c.String(nullable: false, maxLength: 128),
UserId = c.String(nullable: false, maxLength: 128),
})
.PrimaryKey(t => new { t.LoginProvider, t.ProviderKey, t.UserId })
.ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true)
.Index(t => t.UserId);
}
public override void Down()
{
DropForeignKey("dbo.AspNetUserRoles", "UserId", "dbo.AspNetUsers");
DropForeignKey("dbo.AspNetUserLogins", "UserId", "dbo.AspNetUsers");
DropForeignKey("dbo.AspNetUserClaims", "UserId", "dbo.AspNetUsers");
DropForeignKey("dbo.AspNetUserRoles", "RoleId", "dbo.AspNetRoles");
DropIndex("dbo.AspNetUserLogins", new[] { "UserId" });
DropIndex("dbo.AspNetUserClaims", new[] { "UserId" });
DropIndex("dbo.AspNetUsers", "UserNameIndex");
DropIndex("dbo.AspNetUserRoles", new[] { "RoleId" });
DropIndex("dbo.AspNetUserRoles", new[] { "UserId" });
DropIndex("dbo.AspNetRoles", "RoleNameIndex");
DropTable("dbo.AspNetUserLogins");
DropTable("dbo.AspNetUserClaims");
DropTable("dbo.AspNetUsers");
DropTable("dbo.AspNetUserRoles");
DropTable("dbo.AspNetRoles");
}
}