开发者

IQueryable contains any of string array

I am not sure 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 sure 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 ?


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.


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 }));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜