- There is no initial data in my WPF (netcore3.1-windows) EFCore 5 application when I bind AnotherEntity's Name.
- The data does initially load in the same app but with WPF (net40) EFCore 6 Application from the Page's load:
public partial class Entity
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public virtual AnotherEntity AnotherEntity { get; set; }
...
}
...
WPFPage()
{
_entities = DBContext.Entities.ToList();
}
<ListView ItemsSource="{Binding _entities}" ...> ...
<GridView>
<!--with FECore5 no data here. But in EF6 there is.-->
<GridViewColumn DisplayMemberBinding="{Binding Entity.AnotherEntityName}"
Header="Entity"
Width="100"></GridViewColumn>
</GridView>
...
Unless I access and load Another database Entities from AnotherEntities property in the Application code:
public AnotherWPFPage() { _anotherEntities = DBContext.AnotherEntities.ToList(); }
Or if I explicitly set the binding as
<GridViewColumn DisplayMemberBinding="{Binding Entity.AnotherEntity.AnotherEntityName}"
Is this due to the DataBase's scaffolding error by Fluent Api, xaml bindings feature or the EntityFrameworkCore's feature?.
CodePudding user response:
I don't have an access your full code base, but I presume it's due to EF Core lazy loading feature and its dynamic proxies might not work with WPF binding. In your code change this
_entities = DBContext.Entities.ToList();
To this
_entities = DBContext.Entities
.Include(x => x.AnotherEntity)
.ToList();