I use asp.net core EF.
I have two models.
[1] the first one is employee which inherits IdentityUser and extending it.
[2] the second one is DocumentIn which has employee's key
note: they are not related
the problem:
I need to view all DocumentIn but with employee's names, not keys
next are my two models respectively (with comments included to demonstrate Primary and Foreign keys)
Employee inheriting from IdentityUser
public class Employee: IdentityUser
{
// this primary key (Id) is identified as a foreign key twice in the next model (Document In)
// but with different names
// the names are [EmpFrom] and [EmpTo]
[Key]
public override string Id { get => base.Id; set => base.Id = value; }
//-------------------------------------------------------------------------------------------
[EmailAddress]
public override string Email { get => base.Email; set => base.Email = value; }
public string HomePhone { get; set; }
public string EmpName { get; set; }
public int? DivID { get; set; }
[ForeignKey("DivID")]
public Division division { get; set; }
public string Password { get; set; }
[NotMapped]
public string ConfirmPassword { get; set; }
}
DocumentIn
public class DocumentIn
{
[Key]
public int DocInID { get; set; }
public string DocName { get; set; }
public string Notes { get; set; }
public string BarCode { get; set; }
public DateTime ActionDate { get; set; }
public DateTime DueDate { get; set; }
// here I use these names to contains employees Id which is GUID of IdentityUser
public string EmpFrom { get; set; }
public string EmpTo { get; set; }
}
Important:
I use EF concept, DbContext to get DocumentIn
however, I use UserManager on the other hand to get employees
like the following
gitting DocumentIn using _context
// _TableView is a ViewModel which has this attripute
// public List<DocumentIn> DocumentsInList { get; set; }
_TableView.DocumentsInList = await _context.DocumentIn.Where(bla bla bla).ToListAsync();
gitting employees using UserManager
List<Employee> Emps = await userManager.Users.ToListAsync();
Now, I need to include Emp with DocumentsInList's query to read all documents with the names of employees, not with their Id.
In other words, I need to view EmpName from Employee rather than EmpFrom and EmpTo in the above LINQ query.
I already made the next LINQ query but I don't know how to replace EmpFrom and EmpTo from DocumentIn with EmpName from Employee
// -------- all users
List<Employee> Emps = await userManager.Users.ToListAsync();
_TableView.DocumentsInList = await _context.DocumentIn.Include(e => Emps).ToListAsync();