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 Ind开发者_StackOverflow社区ividualName
{
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.
I think you would be looking for....
searchExpressions.Add(new SearchExpression("Individual
.IndividualNames
.Select(GivenName)",
ComparisonOperator.Contains, "Test");
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
im not sure this is aplicable in your case, but maybe this lambda?
Individual.IndividualNames.Where(x => x.GivenName == "Test")
精彩评论