- 當我系結另一個物體的名稱時,我的 WPF(netcore3.1-windows)EFCore 5 應用程式中沒有初始資料。
- 資料最初在同一個應用程式中加載,但使用來自頁面加載的 WPF (net40) EFCore 6 應用程式:
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 功能導致的資料庫腳手架錯誤嗎?。
uj5u.com熱心網友回復:
我無法訪問您的完整代碼庫,但我認為這是由于EF Core延遲加載功能所致,其動態代理可能不適用于 WPF 系結。在你的代碼中改變這個
_entities = DBContext.Entities.ToList();
對此
_entities = DBContext.Entities
.Include(x => x.AnotherEntity)
.ToList();
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/323719.html
下一篇:xamarin形式的超鏈接按鈕
