在 Entity Framework 中的 IncludeFilter 上使用 AND (&&) 运算符加上不带回嵌套/子对象
Using the AND (&&) operator on IncludeFilter in Entity Framework Plus not bringing back nested / child object
我刚刚开始使用 Entity framework Plus 来恢复具有一组复杂约束/要求的数据。我能够成功使用它,但是在 IncludeFilter() 方法内部使用 && 运算符时,我无法获取要返回的嵌套/子对象。
我有一个 Company 对象 > 每个都有多个 CommunicationLink 对象 > 每个 CommunicationLink 对象都有一个 Communication 对象。我已经计算出添加多个 'Include Filters' 可用于复制 'Or' 功能 (||),但我不能在我的生活中使用 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 记录.过滤后的结果运行良好,但是通信对象(我希望通过 .Select() 方法获得)对于这些记录返回为 null。
今天早上纠结了一段时间后,我解决了。
//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.Communication) //forgot Communication!!
)
.Where(co =>
string.Equals(co.Type, "Customer")
&& string.Equals(co.Status, "Active")
&& co.Deleted != 1
)
.OrderBy(c => c.Name);
我刚刚开始使用 Entity framework Plus 来恢复具有一组复杂约束/要求的数据。我能够成功使用它,但是在 IncludeFilter() 方法内部使用 && 运算符时,我无法获取要返回的嵌套/子对象。
我有一个 Company 对象 > 每个都有多个 CommunicationLink 对象 > 每个 CommunicationLink 对象都有一个 Communication 对象。我已经计算出添加多个 'Include Filters' 可用于复制 'Or' 功能 (||),但我不能在我的生活中使用 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 记录.过滤后的结果运行良好,但是通信对象(我希望通过 .Select() 方法获得)对于这些记录返回为 null。
今天早上纠结了一段时间后,我解决了。
//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.Communication) //forgot Communication!!
)
.Where(co =>
string.Equals(co.Type, "Customer")
&& string.Equals(co.Status, "Active")
&& co.Deleted != 1
)
.OrderBy(c => c.Name);