我只是在 Entity framework Plus 中找到自己的脚,以带回具有一组复杂约束/要求的数据。我能够成功使用它,但是在 IncludeFilter() 方法中使用 && 运算符时,我无法返回嵌套/子对象。
我有一个 Company 对象 > 每个都有多个 CommunicationLink 对象 > 每个 CommunicationLink 对象都有一个 Communication 对象。我已经确定添加多个“包含过滤器”可用于复制“或”功能(||),但我无法终生使用 AND 运算符来过滤结果并获取嵌套对象通过。下面是示例代码:
示例 1:
//2 WHERE CLAUSES
var companiesData = _dbContext.Companies
.IncludeFilter(comp => comp.CommunicationLinks
.Where(cmli =>
string.Equals(cmli.Communication.Action, "PhoneOut")
)
.Where(cmli => cmli.UserId == comp.AccountManager)
.Select(comm => comm) //I believe this is where the problem lies
)
.Where(co =>
string.Equals(co.Type, "Customer")
&& string.Equals(co.Status, "Active")
&& co.Deleted != 1
)
.OrderBy(c => c.Name);
示例 2:
//USING && INSTEAD OF 2 WHERE CLAUSES
var companiesData = _dbContext.Companies
.IncludeFilter(comp => comp.CommunicationLinks
.Where(cmli =>
string.Equals(cmli.Communication.Action, "PhoneOut")
&& cmli.UserId == comp.AccountManager
)
.Select(comm => comm) //I believe this is where the problem lies
)
.Where(co =>
string.Equals(co.Type, "Customer")
&& string.Equals(co.Status, "Active")
&& co.Deleted != 1
)
.OrderBy(c => c.Name);
我正在尝试过滤结果以仅返回子 Communication.Action 字段为“PhoneOut”且 Communication.UserId 等于 Company.AccountManager (Id) 中的值的 CommunicationLink 记录。过滤后的结果运行良好,但是 Communication 对象(我希望使用 .Select() 方法获得)对于这些记录返回为 null。