IQueryable的包含任何字符串数组 [英] IQueryable contains any of string array

查看:287
本文介绍了IQueryable的包含任何字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么IQuerable限制了我,当我尝试搜索数据库中包含字符串从数组中的数据。

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();

它抛出NullReferenceException异常,我不知道该怎么做,以检查是否从数组的任何元素是containd在姓氏或姓名及是什么原因导致这种异常。

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.

我只是猜测,那是因为你不能做一个查询中查询?

推荐答案

您可以做一个查询的查询中。

You can do a query inside a query.

下面是一个嵌套的LINQ查询,我通过谷歌找到的随便举个例子,你的里程可能会有所不同:

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

这篇关于IQueryable的包含任何字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆