I am trying to convert IQueryable
to IEnumerable
using SQL query. I am not sure if it's possible.
我试图使用SQL查询将IQueryable转换为IEnumerable。我不确定是否可能。
var id = "123";
string queryString = "SELECT * FROM c WHERE c.ID = " + id;
var dataSource = new List<Book> {
new Book{ ID = "123", Title = "HarryPotter"}}.AsQueryable();
var expected = dataSource.ConvertToIEnumerable(queryString); //IEnumerable type
The dataSource
variable has type of IQueryable
. Is there any way to pass the queryString
variable in order to convert the expected
variable has type of IEnumerable
?
dataSource变量的类型为IQueryable。有没有办法传递queryString变量才能转换预期变量的IEnumerable类型?
1 个解决方案
#1
3
What you are trying to do is to query List<T>
in memory using sql. I do not believe that there is a built-in way in .NET Framework.
您要做的是使用sql在内存中查询List
What you can do is to use LINQ that provides SQL-like or lambda syntax to collections.
您可以做的是使用为集合提供类似SQL或lambda语法的LINQ。
var id = "123";
var dataSource = new List<Book>
{
new Book{ ID = "123", Title = "HarryPotter"}
};
var find = dataSource.Where(i => i.ID == id);
#1
3
What you are trying to do is to query List<T>
in memory using sql. I do not believe that there is a built-in way in .NET Framework.
您要做的是使用sql在内存中查询List
What you can do is to use LINQ that provides SQL-like or lambda syntax to collections.
您可以做的是使用为集合提供类似SQL或lambda语法的LINQ。
var id = "123";
var dataSource = new List<Book>
{
new Book{ ID = "123", Title = "HarryPotter"}
};
var find = dataSource.Where(i => i.ID == id);