I want to display in a Column navigation property like city_Name I wrote this code but Nothing happens
<DataGrid Margin="210,15" Grid.Row="1" CanUserAddRows="False" AutoGenerateColumns="False" Name="dg_Super" RowHeight="20" >
<DataGrid.Columns>
<DataGridTextColumn Width="*" Header="Super Name" Binding="{Binding Path=SupermarketName, Mode=OneTime}"></DataGridTextColumn>
<DataGridTextColumn Width="*" Header="City" Binding="{Binding Path=City1.CityName, Mode=OneTime}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
and the the c# code
var super = mh.Supermarkets;
dg_Super.ItemsSource = super.ToList();
City1 is anavigation property from ef model. Please what is wrong here?
In your query - perhaps add the Include method:
var super = mh.Supermarkets.Include("City1")
Because EF doens't know it has to get data from the "City" table. If the query uses a field from the City table, you don't have to include Include("City")
- EF can then detect that you need data from the table, thus it automaticly loads the City table
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.