如何解决在Entity Framework Plus中在IncludeFilter上使用AND&&运算符不会带回嵌套/子对象
我只是想用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。
解决方法
今天早晨在挣扎了一段时间之后,我解决了它。
//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);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。