как вывести данные вместо id связанных таблиц WPF
есть таблицы связанные между собой в БД (SQLite), также классы
public class User : INotifyPropertyChanged
{
public int Id { get; set; }
public int? RoleId { get; set; }
public Role Role { get; set; }
public int? OfficeId { get; set; }
public virtual Office Office { get; set; }
private string email;
public string Email
{
get { return email; }
set { email = value; OnPropertyChanged("Email"); }
}
private string password;
public string Password
{
get { return password; }
set { password = value; OnPropertyChanged("Password"); }
}
private string lastname;
public string Lastname
{
get { return lastname; }
set { lastname = value; OnPropertyChanged("Lastname"); }
}
private string birthdate;
public string Birthdate
{
get { return birthdate; }
set { birthdate = value; OnPropertyChanged("Birthdate"); }
}
private string active;
public string Active
{
get { return active; }
set { active = value; OnPropertyChanged("Active"); }
}
private string firstname;
public string Firstname
{
get { return firstname; }
set { firstname = value; OnPropertyChanged("Firstname"); }
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string prop = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));
}
}
public class Role : INotifyPropertyChanged
{
public int Id { get; set; }
private string title;
public virtual ICollection<User> Users { get; set; }
public Role()
{
Users = new List<User>();
}
public string Title
{
get { return title; }
set
{
title = value;
OnPropertyChanged("Title");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string prop = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));
}
}
public class Office : INotifyPropertyChanged
{
public int Id { get; set; }
public int? CountrieId { get; set; }
public Countrie Countrie { get; set; }
public virtual ICollection<User> Users { get; set; }
public Office()
{
Users = new List<User>();
}
private string title;
public string Title
{
get { return title; }
set { title = value; OnPropertyChanged("Title"); }
}
private string phone;
public string Phone
{
get { return phone; }
set { phone = value; OnPropertyChanged("Phone"); }
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName]string prop = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));
}
}
public class Countrie : INotifyPropertyChanged
{
public int Id { get; set; }
public virtual ICollection<Office> Offices { get; set; }
public Countrie()
{
Offices = new List<Office>();
}
private string name;
public string Name
{
get { return name; }
set { name = value; OnPropertyChanged("Name"); }
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName]string prop = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));
}
}
и контекст
using System.Data.Entity;
namespace Session1
{
public class ContextDB : DbContext
{
public ContextDB() : base("MyConn") { }
public DbSet<Role> Roles { get; set; }
public DbSet<User> Users { get; set; }
public DbSet<Office> Offices { get; set; }
public DbSet<Countrie> Countries { get; set; }
}
}
и еще xaml код
<DataGrid x:Name="DataGridView" ItemsSource="{Binding}" AutoGenerateColumns="False" Width="auto">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Firstname}"/>
<DataGridTextColumn Header="Last name" Binding="{Binding Lastname}"/>
<DataGridTextColumn Header="Age" Binding="{Binding Birthdate}"/>
<DataGridTextColumn Header="User role" Binding="{Binding RoleId}"/>
<DataGridTextColumn Header="Email address" Binding="{Binding Email}"/>
<DataGridTextColumn Header="Office" Binding="{Binding OfficeId}"/>
</DataGrid.Columns>
</DataGrid>
код к нему
ContextDB db;
public AdminPanel()
{
InitializeComponent();
db = new ContextDB();
db.Users.Load();
DataContext = db.Users.Local.ToBindingList();
}
при запуске выводятся
как сделать так, чтобы вместо id в столбцах User role и office выводились данные
например так
