Answer the question
In order to leave comments, you need to log in
How to display from the database to the datagrid (WPF + Entity)?
Good day, the problem is that when I query the database, I get an exception, where did I make a mistake?
The Model contains
the Client
namespace WpfApplication2.Models
{
[Table("Client")]
public class Client
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
[Column("Id")]
public int Id { get; set; }
[ForeignKey("Id")]
[Column("ClientName")]
public string ClientName { get; set; }
[Column("DateBirth")]
public string DateBirth { get; set; }
public ICollection<Phone> Phones { get; set; }
}
}
namespace WpfApplication2.Models
{
[Table("Phone")]
public class Phone
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
[Column("Id")]
public int Id{ get; set; }
[Column("Id_Client")]
public int Id_Client { get; set; }
[ForeignKey("Id_Client")]
[Column("PhoneNumber")]
public string PhoneNumber { get; set; }
public Client Clients { get; set; }
}
}
namespace WpfApplication2.Models
{
class ClientContext : DbContext
{
public ClientContext(): base("DefaultConnection")
{
}
public DbSet<Client> Clients { get; set; }
public DbSet<Phone> Phones { get; set; }
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var kk = db.Clients.ToList();
var dd = db.Phones.ToList();
personGrid.ItemsSource = kk;
personGrid.ItemsSource = dd;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question