asp.net-mvc – AspNet如何与我的模型识别
我正在尝试在
the External Authentication Services (C#)上完成本教程.我需要一些初步的解释才能继续.查看MVC5的默认模板,我看到了这个:
// You can add profile data for the user ... public class ApplicationUser : IdentityUser { public string HomeTown { get; set; } public DateTime? BirthDate { get; set; } } 如果我想将其称为User而不是ApplicationUser,该怎么办?也许我想添加导航属性,以便我可以与其他模型建立关系?此外,当我查看表时,名称是AspNetUsers而不是ApplicationUser.最后,如果我想使用自己的上下文怎么办? 谢谢你的帮助. 解决方法
您可以更改为所需的任何名称,只需确保将ApplicationUser替换为名称即可.
如果您有一个类调用地址,您想将addressId添加为外键,请参阅以下内容: public class Address { public int Id { get; set; } public string Street { get; set; } } public class User : IdentityUser { public string HomeTown { get; set; } public DateTime? BirthDate { get; set; } public int AddressId { get; set; } [ForeignKey("AddressId")] public virtual Address Address { get; set; } } public class ApplicationDbContext : IdentityDbContext<User> { public ApplicationDbContext() : base("DefaultConnection") { } public DbSet<Address> Addresses { get; set; } }
ASP.NET Identity继承自ASP.NET成员资格系统.注册新用户时 How can I change the table names when using Visual Studio 2013 ASP.NET Identity?
您可以创建自己的DBContex,MVC 5允许您拥有多个DBContext,例如ApplicationDbContext和DataDbContext(自定义DbContext). public class Blog { public int BlogId { get; set; } public int Title { get; set; } } public class MyDbContext : DbContext { public MyDbContext() : base("DefaultConnection") { } public DbSet<Blog> Blogs { get; set; } } 注意:您可能需要使用EF迁移,请参阅此处的详细信息: ASP.Net Identity customizing UserProfile (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net – 在Response.RedirectToRoute之后跳过页面执行的
- asp.net – GridView中的TemplateField标题
- asp.net-mvc – 使用缓存配置文件缓存ChildActions将不起作
- asp.net-mvc – 有没有办法让RoutePrefix以可选参数开头?
- 使用.NET 4.5的ASP.Net成员身份和实体框架迁移的问题
- asp.net – 在asp:超链接中分配声明值的问题 错误:这不是
- asp.net – “共享主机中的”LOG_BACKUP“的数据库的事务日
- asp.net – AppPool关闭自己
- asp.net – 使用字符串列表绑定GridView
- asp.net – 多个用户控件和JavaScript