One Bindinglist from multible DbSets to gridview

YouElz 1 Reputation point
2022-09-03T14:17:53.717+00:00

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;  
Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
697 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,234 questions
{count} votes