I have added an OrganisationId field to AspNetUsers table which is a ForeignKey from Organisation Table. When I display the list of users, I need to add a column Organisation Name to the table display.
This is the IdentityModels
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; }
}
}
Here is the controller which I include the Organisation in the query, however, I got the error saying Invalid object name 'dbo.Organisations'
var selectedUserIds = from user in UserManager.Users
select user;
selectedUserIds.Include(x => x.Roles).Include(x=>x.Organisations).ToList();
I have Organisation table in the database. Can anyone tell me whats wrong on this one? Thank you in advance.
https://stackoverflow.com/questions/29793926/one-to-many-relationship-between-aspnetusers-identity-and-a-custum-table – Ehasanul Hoque Jan 10 '18 at 04:38