c# - 在 Linq 中访问导航属性返回 - “由于对象的当前状态,操作无效”
问题描述
我不确定这是否是一个合法的错误,或者我没有看到明显的东西。我正在使用 EF Core 预览版 8。这是我的代码:
var customers = dbContext.Customers
.Include(c => c.Addresses)
.Include(c => c.Contacts)
.Where(c => c.TenantId == tenant.Id);
if (!customerSearchCriteria.AccountSurname.IsEmpty())
{
customers = customers.Where(c => c.Contacts.Any(a =>
a.Surname.RemoveWhitespace().NullSafeToLower()
.Contains(customerSearchCriteria.AccountSurname.RemoveWhitespace().NullSafeToLower())));
}
return customers.Skip(customerSearchCriteria.start).Take(customerSearchCriteria.length).ToList();
如果我完全删除中间的条件,查询工作正常。一旦我触摸联系人或地址属性,它将返回上述异常。有什么线索吗?
我做了一些研究,并在 github 上发现了一些关于类似问题的链接,但不确定是否是相同的情况:
解决方案
推荐阅读
- python - 如何有效地将列表转换为地图?
- laravel - 单击背景时如何防止laravel jetstream模式关闭?
- c# - 将两个输入分配给 SQL 表的单个列
- java - 更改谷歌表格的背景颜色
- python-3.x - 遍历包含具有不同子字符串匹配的字符串但未获得正确输出的两个不同列的行
- python - 在 RandomForestRegressor 上使用 RFECV 解决回归问题
- multithreading - 创建 TThread 没有进入我的 Create() 方法
- android - 在 Jetpack Compose 中的可组合项中单击按钮时多次显示 AdMob 插页式广告
- laravel - 如何在 Laravel Socialite 中获取已登录 Google 帐户的索引?
- javascript - “未捕获的类型错误:单击数字按钮时无法读取未定义的属性(读取'toString')