链接到实体:嵌套 .Any()
在存储库中,我需要搜索联系人 (c) 的功能,以获取搜索条件 (sc) 中定义的其他功能的集合。表达式函数如下所示:
// no Problem from here --->
c => c.firstName.StartsWith(sc.FirstName)
&& c.lastName.StartsWith(sc.LastName)
&& c.addressData.Any(a => a.City.StartsWith(sc.City))
&& c.addressData.Any(a => a.StreetAddr.StartsWith(sc.Street))
&& c.addressData.Any(a => a.ZIPCode.StartsWith(sc.ZipCode))
&& c.visit.Any(v=> v.vStartDate >= sc.VisitTimeIntervalStart)
&& c.visit.Any(v => v.vStartDate <= sc.VisitTimeIntervalEnd)
// <-- to here but this ->
&& c.contact2feature.Any(
c2f => sc.FeaturePattern.Any(
` fp => fp.Item1.featureID == c2f.feature.featureID))
// thows: System.Reflection.TargetInvocationException
// Inner: Unable to process the type System.Tuple 2[], because it has no known mapping to the value layer.
In a repository I need to search a contact (c)'s features for a collection of other features defined in a searchCriteria (sc). The Expression Func looks like this:
// no Problem from here --->
c => c.firstName.StartsWith(sc.FirstName)
&& c.lastName.StartsWith(sc.LastName)
&& c.addressData.Any(a => a.City.StartsWith(sc.City))
&& c.addressData.Any(a => a.StreetAddr.StartsWith(sc.Street))
&& c.addressData.Any(a => a.ZIPCode.StartsWith(sc.ZipCode))
&& c.visit.Any(v=> v.vStartDate >= sc.VisitTimeIntervalStart)
&& c.visit.Any(v => v.vStartDate <= sc.VisitTimeIntervalEnd)
// <-- to here but this ->
&& c.contact2feature.Any(
c2f => sc.FeaturePattern.Any(
` fp => fp.Item1.featureID == c2f.feature.featureID))
// thows: System.Reflection.TargetInvocationException
// Inner: Unable to process the type System.Tuple 2[], because it has no known mapping to the value layer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,
sc.FeaturePattern
似乎是一个Tuple
,这意味着它不是实体模型/EDMX 的一部分。因此 LINQ to Entities 不知道如何将其转换为 SQL。但你可以很容易地解决这个问题:Well,
sc.FeaturePattern
appears to be aTuple
, which means it's not part of your entity model/EDMX. So LINQ to Entities doesn't know how to translate it to SQL. But you can pretty easily work around that: