Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

how to bind data from entity framework to inner data grid?

$
0
0

I have 2 tables Customer and Order customer id is a primary key and it has foriegn key relationship with order key. so i want to display customers in data grid and order in RowDetailsTemplate which consists of another data grid.

Below is the XAML

<Grid><DataGrid AutoGenerateColumns="True" Name="dataGrid1"><DataGrid.RowDetailsTemplate><DataTemplate><DataGrid ItemsSource="{Binding Order}" AutoGenerateColumns="True"/></DataTemplate></DataGrid.RowDetailsTemplate></DataGrid></Grid>

In the codebehind i write the following code

        public MainWindow()
        {
            InitializeComponent();
            SampleDBEntities1 context = new SampleDBEntities1();
            dataGrid1.ItemsSource = context.Customers.ToList();           
        }

Here i am unable to bind the inner datagrid.

Below are Entityframework generated classes for customer and order

    public partial class Customer
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string City { get; set; }
        public virtual Order Order { get; set; }
    }

    public partial class Order
    {
        public int ID { get; set; }
        public string Number { get; set; }
    
        public virtual Customer Customer { get; set; }
    }


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>