One Bindinglist from multible DbSets to gridview
YouElz
1
Reputation point
Just wondering if it is possible to bind 2 DbSets to one data grid view leveraging BindingList.
public virtual DbSet<Candidate> Candidates { get; set; } = null!;
public virtual DbSet<Candimmigration> Candimmigrations { get; set; } = null!
;
one-to-one relationship -> Candidate and Candimmigration;
public partial class Candidate
{
[Key]
[Column("ID")]
public int Id { get; set; }
[StringLength(20)]
public string FirstName { get; set; } = null!;
[StringLength(20)]
public string? MiddleName { get; set; }
[StringLength(20)]
public string LastName { get; set; } = null!;
[Column(TypeName = "date")]
public DateTime? DateOfBirth { get; set; }
[InverseProperty("Candidate")]
public virtual Candimmigration Candimmigration { get; set; } = null!;
}
I have the below code that I would like to convert into BindingList of 2 DbSets which bind to one grid view dgvCandidates
.
var candiatesList = await _dbContext.Candidates
.Include(i => i.Candimmigration)
.Select(s => new
{
Id = s.Id,
FirstName = s.FirstName,
LastName = s.LastName,
DOB = s.DateOfBirth,
VisaNo = s.Candimmigration.VisaNo,
PassportNo = s.Candimmigration.PassportNo,
}).ToListAsync();
dgvCandidates.DataSource = candiatesList;