在存储库中,我需要在联系人(C)的特征中搜索在searchCriteria (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. 发布于 2011-02-01 23:28:05
sc.FeaturePattern似乎是一个Tuple,这意味着它不是实体模型/EDMX的一部分。因此LINQ to Entities不知道如何将其转换为SQL。但是你可以很容易地解决这个问题:
// extract scalar values from tuple
var featureIds = sc.FeaturePattern.Select(fp => fp.Item1.featureId);
// now do query
// ...
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 => featureIds.Contains(
fid => fid == c2f.feature.featureID)) https://stackoverflow.com/questions/4863896
复制相似问题