How to query an array of objects ?

25 views
Skip to first unread message

Nima Ha

unread,
Oct 25, 2014, 5:19:28 AM10/25/14
to rav...@googlegroups.com
Here's a Person object :

public class Person
{
       public string FirstName{get;set;}
       public string LastName{get;set;}
       public string[] NickNames{get;set;} 
}

Suppose that we want to query all the persons with a certain nickname.("Tough Guy" for example)
I thought I could write it like this :

var query=session.Query<Person>().Where(p=>p.NickNames.Contains("Tough Guy"));

but this statement generates an empty query. 
I know I could use Any() but the problem is that I want to translate a string into a Linq query (For example : FirstName.Equals("John") AND NickNames.Contains("Tough Guy")) using Dynamic Linq Library and this library doesn't support extension methods such as Any ( unless I modify its source which I think it would be the last option)

So the question is how I can search for Though Guys in a list of documents ? :)

Chris Marisic

unread,
Oct 27, 2014, 12:19:35 PM10/27/14
to rav...@googlegroups.com
I have used Dynamic Linq for expressing simple, strongly typed query options. For complex scenarios just drop down to the lucene api.
Reply all
Reply to author
Forward
0 new messages