I need to display by id the ingredients from a linked database table.
I am using Entity Framework Core with generated scaffolds for the database . The code below is simplified version of the entity classes I’m working with.
public partial class Recipe
{
public Recipe()
{
InterchangeabilityIngredients = new HashSet<InterchangeabilityIngredients>();
}
public int Id { get; set; }
public int IdBrand { get; set; }
public int IdIngredient { get; set; }
public double MassPart { get; set; }
public double PercentWeight { get; set; }
public virtual RubberBrand IdBrandNavigation { get; set; }
public virtual Ingredient IdIngredientNavigation { get; set; }
public virtual ICollection<InterchangeabilityIngredients> InterchangeabilityIngredients { get; set; }
}
IngredientsBrandGrid.ItemsSource = db.Recipe.AsQueryable().Where(x => x.IdBrand == currentbrid).ToList();
My DataGrid simplistically looks like this:
<DataGrid x:Name="IngredientsBrandGrid" SelectionMode="Single" IsReadOnly="True" HorizontalAlignment="Left" Margin="0,0,0,60" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="NameIngredient" Binding="{Binding IdIngredientNavigation.NameIngredient}" Width="200">
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="TextBlock.TextWrapping" Value="Wrap" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="MassPart" Binding="{Binding MassPart}"/>
<DataGridTextColumn Header="PercentWeight" Binding="{Binding PercentWeight}"/>
</DataGrid.Columns>
</DataGrid>
But for some reason the column appears empty
enter image description here
I also tried adding incude() to the query, but the result is the same
IngredientsBrandGrid.ItemsSource = db.Recipe.Include(x=>x.IdIngredientNavigation).AsQueryable().Where(x => x.IdBrand == currentbrid).ToList();
Miriskava is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.