0
我使用EF 6個對象,有一個帳戶,有些必須設置對象C#EF只傳回有物體
的關係,但不是所有的帳戶有一個設置對象。 如何返回所有具有設置對象的帳戶?
using (IUnitOfWork uw = _uwf.Create())
{
Dictionary<string, Account> accounts;
accounts = uw.Account.All.Where(ac=>ac.Setting.IsEnabled).ToDictionary(a => a.Id, a => a); <--- this is the problem, just want the ones that have a Setting otherwise im getting null reference thrown.
}
我的倉庫
public class AccountRepository : MarkForDeleteRepository<DomainObjects.Account>, IAccountRepository
{
public override IEnumerable<Account> All
{
get
{
return
RepositorySet.Include("Country")
.Include("Setting")
}
}
我們如何檢查'null'? 'ac.Setting!= null && ac.Setting.IsEnabled','ac.Setting?.IsEnabled == true'等 –