Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: , +
Hey guys

I'm using EF and some related tables and I'm supposed to get the result from all of them and put it on a grid. The tables are Tara(ID, Name), Judet(ID,ID_Tara, Name), Oras(ID, ID_Judet, Name), CodPostal(ID, ID_Oras, CodPostal), Adresa(ID, ID_CodPostal, ID_Oras, Detalii). I hope you understand the relationship betwen them.
Now I must write a query with the parameter ID(Adresa) and bind the result to the datagrid and I must use Include(). I have the example below:

XML
public List<Adresa> GetFullAddress(int id)
        {
            var adresa = be.Adresa.Include("CodPostal.Oras.Judet.Tara").Where(a => a.ID == id);
            return adresa.ToList();
        }


The column definitions are the following
What I don't know is what to enter as FieldName except for the first one because the other are in the related tables


XML
<grid:AgDataGrid.Columns>
                    <grid:AgDataGridTextColumn TextWrapping="Wrap" FieldName="Detalii" MinColumnWidth="70" HeaderStyle="{StaticResource ColumnHeaderStyleBlue}"/>
                    <grid:AgDataGridTextColumn TextWrapping="Wrap" FieldName="CodPostal" MinColumnWidth="70" HeaderStyle="{StaticResource ColumnHeaderStyleBlue}"/>
                    <grid:AgDataGridTextColumn TextWrapping="Wrap" FieldName="Oras" MinColumnWidth="70" HeaderStyle="{StaticResource ColumnHeaderStyleBlue}"/>
                    <grid:AgDataGridTextColumn TextWrapping="Wrap" FieldName="Judet" MinColumnWidth="70" HeaderStyle="{StaticResource ColumnHeaderStyleBlue}"/>
                    <grid:AgDataGridTextColumn TextWrapping="Wrap" FieldName="Tara" MinColumnWidth="70" HeaderStyle="{StaticResource ColumnHeaderStyleBlue}"/>
                </grid:AgDataGrid.Columns>


I am using services
C#
private void bsc_GetFullAddressCompleted(object sender, GetFullAddressCompletedEventArgs e)
        {
            gridBorderouTara.DataSource = e.Result;
        }


I solved the problem using stored procedure but I am supposed to do it this way :(
Thank you and I hope I gave enough information
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900