Linq to sql ExecuteQuery () as IQueryable

The ExecuteQuery () method returns IEnumerable, but is there any way to return it IQueryable?

+3
source share
2 answers

Well, you can call AsQueryable, but it will not do any good. The problem is that when used, the ExecuteQueryquery is not compound, because LINQ to SQL does not "understand" it as such.

One of the main goals IQueryable<T>is the ability to combine different aspects of a query, and then LINQ to SQL can convert them into a single SQL query. It just doesn't work when one of the request bits is effectively opaque.

+8
source

, IQueryable. . :

public IQueryable<Data> GetData()
    string query = @"select ...";
    object[] parameters = new object[...]{...};
    var resultQuery = this.DataContext.ExecuteQuery<SICDB.Data>(query, parameters);
    var tempList = resultQuery .ToList();
    return tempList.AsQueryable();
}
+1

Source: https://habr.com/ru/post/1711609/


All Articles