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 – 在项目之间共享aspx页面
- asp.net-core – 如何使用.net Core设置离线开发
- asp.net – 加密ASP .NET 2.0和SQL Server 2005中的工资值
- asp.net – 评论未使用的代码会不会给我的页面带来任何方式
- asp.net – 如何MSDeploy构建的网站包到一个处女IIS网站
- asp.net-web-api – 认证/授权MVC 5和Web API – Katana /
- asp.net-mvc-2 – 在调用EditorFor(…)时隐藏公共属性的编辑
- asp.net-mvc – ASP.Net MVC是否运行在ASP.NET 2.0之上?
- asp.net-identity – 保护整个ASP.NET 5 MVC 6应用程序
- asp.net-mvc – Mvc Mini Profiler请求带有和不带有RouteBa
- 使用ASP.Net MVC将图像上传到SQL Server 2005?
- asp.net-mvc-3 – 找不到概念模型类型
- asp.net – Application_EndRequest没有找到Sess
- asp.net-mvc – EF代码首先不生成表
- .net – 是否必须在自定义实现中覆盖默认的成员资
- ASP.NET MVC 3 ValidateRequest(false)不能使用F
- asp.net-4.0 – 我可以强制asp设置与id相同的名称
- asp.net-mvc – 我什么时候应该在ASP.NET MVC中创
- asp.net-mvc-3 – 用于创建自定义成员资格提供程
- asp.net-mvc – 使用Visual Studio 2013 Preview
