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>
...
除非我从应用程序代码中的 AnotherEntities 属性访问并加载另一个数据库实体:
public AnotherWPFPage() { _anotherEntities = DBContext.AnotherEntities.ToList(); }
或者如果我明确地将绑定设置为
<GridViewColumn DisplayMemberBinding="{Binding Entity.AnotherEntity.AnotherEntityName}"
这是由于 Fluent Api、xaml 绑定功能或 EntityFrameworkCore 功能的数据库脚手架错误造成的吗?
我无法访问您的完整代码库,但我认为这是由于 EF Core 延迟加载功能及其动态代理可能无法与 WPF 绑定一起使用。 在你的代码中改变这个
_entities = DBContext.Entities.ToList();
对此
_entities = DBContext.Entities
.Include(x => x.AnotherEntity)
.ToList();