【发布时间】:2018-01-10 02:28:17
【问题描述】:
我在 AspNetUsers 表中添加了一个 OrganisationId 字段,它是组织表中的 ForeignKey。当我显示用户列表时,我需要在表格显示中添加一列组织名称。
这是身份模型
using C2T.Model;
namespace C2T.Models
{
// You can add profile data for the user by adding more properties to your ApplicationUser class, please visit https://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
public class ApplicationUser : IdentityUser
{
public int OrganisationId { get; set; }
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 string Firstname { get; set; }
public string Lastname { get; set; }
public virtual Organisation Organisations { get; set; }
}
public class ApplicationRole : IdentityRole
{
public ApplicationRole() : base() { }
public ApplicationRole(string name) : base(name) { }
public string Description { get; set; }
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
public System.Data.Entity.DbSet<C2T.Models.ApplicationRole> IdentityRoles { get; set; }
public System.Data.Entity.DbSet<C2T.Models.RoleViewModel> RoleViewModels { get; set; }
public System.Data.Entity.DbSet<C2T.Model.Organisation> Organisations { get; set; }
}
}
这是我在查询中包含组织的控制器,但是,我收到错误消息 Invalid object name 'dbo.Organisations'
var selectedUserIds = from user in UserManager.Users
select user;
selectedUserIds.Include(x => x.Roles).Include(x=>x.Organisations).ToList();
我在数据库中有组织表。谁能告诉我这个有什么问题?提前谢谢你。
【问题讨论】:
-
我已经关注了那个,但它并没有解决我的问题
标签: c# asp.net-mvc asp.net-identity relationship