ef-code-first – 如何首先使用代码向Identity默认表AspNetUsers
发布时间:2020-12-16 09:19:49 所属栏目:asp.Net 来源:网络整理
导读:我是Identity framework和Code First方法的新手.现在我在VS 2015上创建一个新的MVC5项目时使用默认项目. 我运行项目时生成的默认表格很好,但我希望它与其他项目一起生成一个名为tbSkills(Id,SkillName)的新表格,它必须与AspNetUsers有多对多的关系. 那么我要
我是Identity framework和Code First方法的新手.现在我在VS 2015上创建一个新的MVC5项目时使用默认项目.
我运行项目时生成的默认表格很好,但我希望它与其他项目一起生成一个名为tbSkills(Id,SkillName)的新表格,它必须与AspNetUsers有多对多的关系. 那么我要写的地方和内容要做到这一点? ps:我在遵循教程后也将Id类型从字符串更改为int,它运行正常. 这是我在IdentityModels.cs文件中的类ApplicationUser中最后尝试过的: public class ApplicationUser : IdentityUser<int,MyUserLogin,MyUserRole,MyUserClaim>,IUser<int> { public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser,int> 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; } // // This following is my added code public ApplicationUser() { Skills = new HashSet<tbSkill>(); } public virtual ICollection<tbSkill> Skills { get; set; } } public class tbSkill { public tbSkill() { Users = new HashSet<ApplicationUser>(); } public int Id; public string SkillName; public virtual ICollection<ApplicationUser> Users { get; set; } } 它以此错误结束: 我已经研究过很多文章,但没有成功. 解决方法
尝试添加技能ID
public class ApplicationUser : IdentityUser<int,DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here return userIdentity; } // // This following is my added code public ApplicationUser() { Skills = new HashSet<tbSkill>(); } public int SkillId {get;set;} public virtual ICollection<tbSkill> Skills { get; set; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 异步处理asp.net mvc,提供客户端进度反馈
- asp.net-mvc – 可靠地处理ASP.NET MVC模型绑定错误
- asp.net – FF和IE不从CSS加载img src
- kendo-ui – Kendo Grid阻止默认请求
- asp.net-mvc-3 – @ Html.TextBoxFor文本框在验证失败后未突
- asp.net – FormsAuthentication.RedirectFromLoginPage与R
- .net – .ToTitleCase不适用于所有大写字符串
- asp.net-web-api – 使用Asp.Net Core WebAPI进行授权
- asp.net-mvc – MVC 4中的ReportViewer部分
- asp.net – html文本框的最大长度是多少?
推荐文章
站长推荐
- asp.net-mvc-4 – 动态更改jQuery不显眼的验证属
- asp.net – 为什么我的jQuery UI datepicker在初
- asp.net-mvc – 工作单元,存储库,注入,使用块
- 多终端数据同步机制设计(一)
- asp.net-mvc – MvcMailer SendAsync阻止ASP.NET
- asp.net CustomValidator从不触发OnServerValida
- asp-classic – 是代码页65001和utf-8同样的东西
- asp.net-core – ASP.NET 5中RegisterObject / Q
- asp.net – 我可以使用msbuild打包带有发布配置文
- asp.net – 在非开发环境中省略从Web API方法返回
热点阅读