EF 中动态搜索表达式的问题
我目前正在使用类似于以下内容的数据结构:
public class Individual
{
//Other properties omitted for brevity sake
public List<IndividualName> IndividualNames {get; set;}
}
并且
public class IndividualName
{
public string FamilyName {get; set;}
public string GivenName {get; set;}
public string MiddleName {get; set;}
}
我正在尝试使用一些动态搜索表达式从我的表示层传递到存储库级别(以实际应用搜索)。
但是,由于个人可以有 1-M 个个人名称,我遇到了一些问题,并且我尝试使用 LINQ 来获取个人的所有个人名称,以便可以查询它们。
例如 - 这就是表达式当前的样子:
searchExpressions.Add(new SearchExpression("Individual
.IndividualNames
.Select(GivenName)
.FirstOrDefault()"
, ComparisonOperator.Contains, "Test");
当前仅确定第一个 individualName 实例中的 GiveName 是否包含“Test”。上面的内容按其应有的方式工作 - 然而,我对如何确定任何 individualNames 是否包含该字符串感到有点困惑。
任何帮助将不胜感激 - 因为我已经尝试了几件事但没有任何运气。
I currently am using a data structures similar to the following:
public class Individual
{
//Other properties omitted for brevity sake
public List<IndividualName> IndividualNames {get; set;}
}
and
public class IndividualName
{
public string FamilyName {get; set;}
public string GivenName {get; set;}
public string MiddleName {get; set;}
}
I am attempting to use some Dynamic search expressions to pass from my presentation layer to repository level (to actually apply the search).
However, I have run into some issues due to the fact that an Individual can have 1-M Individual Names, and I am trying to use LINQ to grab all of an Individual's IndividualNames so they can be queried.
For example's sake - this is what the expression currently looks like:
searchExpressions.Add(new SearchExpression("Individual
.IndividualNames
.Select(GivenName)
.FirstOrDefault()"
, ComparisonOperator.Contains, "Test");
This will currently only determine if the GivenName in the first IndividualName instance Contains "Test". The above works as it should - however I am a bit stuck in terms of how I would be able to determine if Any of the IndividualNames contained the string.
Any help would be appreciated - as I have tried several things without any luck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想您会寻找...。
您还需要将 Contains Aggregate Method 添加到 Dynamic Linq 库。如何执行此操作可以在此处找到。
http: //blog.walteralmeida.com/2010/05/advanced-linq-dynamic-linq-library-add-support-for-contains-extension-.html
I think you would be looking for....
You will also need to add a Contains Aggregate Method to the Dynamic Linq library. How to do this can be found here.
http://blog.walteralmeida.com/2010/05/advanced-linq-dynamic-linq-library-add-support-for-contains-extension-.html
我不确定这是否适用于您的情况,但也许这个 lambda ?
im not sure this is aplicable in your case, but maybe this lambda?