views:

197

answers:

2

I am not shore why IQuerable limits me when I try to search database for data containing string from an array.

objectFactory.Resolve<IUserDao>().Query.
                Where(t => 
                    (spltedInput.Any(val=> t.LastName.Contains(val)) || spltedInput.Any(val=> t.Name.Contains(val))) 
                    && t.MasterCompany.Id == MasterCompanySeted).
                Select(t => new { Name = t.Name + " " + t.LastName, Id = t.Id }).
                AsEnumerable().
                Select(t => new RadComboBoxItemData() { Text = t.Name, Value = t.Id.ToString() })
                .ToArray();

It throws NullReferenceException , I am not shore what to do to check if any elements from the array is containd within LastName or Name and what causes this exception.

I am only guessing that it's because you can't do a query inside a query ?

A: 

I suspect that either your objectFactory or IUserDao is probably Null and that's why you get a NullReferenceException. Have you debugged it, cause the debugger will tell you what object is null.

Tony
nope , it works like a charm I only gave this code so you can see the context , when i changes it to eg.: t.LastName.Contains(spltedInput[0]) it works great.
Jacob
A: 

You can do a query inside a query.

Here's a random example of a nested Linq query that I found through Google, your mileage may vary:

var query = people
    .Where(p => p.ID == 1)
    .SelectMany(p => roles
        .Where(r => r.ID == p.ID)
        .Select(r => new { p.FirstName, p.LastName, r.Role }));
Michael Maddox