iqueryable

IQueryable C# Select

谁都会走 提交于 2019-12-04 18:55:24
问题 this is my code... but i need select only column to display in my Datagridview. I Need the code to select only some columns.. example Select{t => t.usu_Login, t => t.usu_Login} public List<tb_usuario> Get(FilterDefinition filter) { var contexto = new indNET_Entities(); IQueryable<tb_usuario> Consulta = contexto.tb_usuario.AsQueryable<tb_usuario>() .Where(t => t.usu_Ativo == 1) .OrderBy(t => t.usu_Login); return Consulta.ToList(); } 回答1: If you only want a limited number of columns and you

Force an IQueryable to execute?

旧巷老猫 提交于 2019-12-04 16:27:52
问题 I have a method that 'has no translation to SQL' that I want to perform on an IQueryable, is there a way to force the IQueryable to execute without having to store it in some intermediate class? 回答1: Is the problem that you want your method to execute locally rather than in the database? If so, AsEnumerable is your friend. It's a very simple method, something like: public IEnumerable<T> AsEnumerable(IEnumerable<T> source) { return source; } The important thing is that it makes the compile

Differences when using IEnumerable and IQueryable as a type of ObjectSet

会有一股神秘感。 提交于 2019-12-04 11:43:24
问题 As I understand it when I use LINQ extension methods (with lambda expression syntax) on IQueryable that is in the fact instance of ObjectSet they are translated into LINQ to SQL queries. What I mean is that command IQueryable<User> users = db.UserSet; var users32YearsOld = users.Where(user => user.Age == 32); is exactly the same as IQueryable<User> users = db.UserSet; var users32YearsOld = from user in users where user.Age == 32 select user; So non of them hits database until they

Entity Framework - IQueryable to DataTable

社会主义新天地 提交于 2019-12-04 11:03:18
I'm trying to convert an IQueryable object to a DataTable . Here's an example of a query that I would like to convert to a DataTable : var query = DbContext.SomeObjectSet.Select(x => new { PropertyName1 = x.ColumnName1, PropertyName2 = x.ColumnName2 }); Please note the anonymous object that is created in the Select method and the names of the properties: new { PropertyName1 = x.ColumnName1, PropertyName2 = x.ColumnName2 } After Googling this issue, I came across the following code that converts an IQueryable object to a DataTable : public static DataTable EntityToDatatable(this IQueryable

Convert Dataset to IQueryable<T> or IEnumerable<T>

旧街凉风 提交于 2019-12-04 09:19:36
问题 Since there is no Linq to DB2 yet (c'mon IBM!), and I want to deal with IQueryables or IEnumerables in my code, how would I convert a DataTable to an IQueryable? Or an IEnumerable? I have an interface and a class that matches the columns in the datatable... IQueryable<IMyData> GetAS400Data(..parameters..) { DataSet d = GetData(); ... //Some code to convert d to IQueryable<IMyData> } DataTable.Rows does not support .AsQueryable, since MSFT yanked it, so I'm not sure what to do here. 回答1: table

How can I write a clean Repository without exposing IQueryable to the rest of my application?

人走茶凉 提交于 2019-12-04 07:48:07
问题 So, I've read all the Q&A's here on SO regarding the subject of whether or not to expose IQueryable to the rest of your project or not (see here, and here), and I've ultimately decided that I don't want to expose IQueryable to anything but my Model. Because IQueryable is tied to certain persistence implementations I don't like the idea of locking myself into this. Similarly, I'm not sure how good I feel about classes further down the call chain modifying the actual query that aren't in the

Dynamic Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> Expression

﹥>﹥吖頭↗ 提交于 2019-12-04 07:22:07
I am using patterns mentioned here http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application And i am using method below to query EF public virtual IEnumerable<TEntity> Get( Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = "") { IQueryable<TEntity> query = dbSet; if (filter != null) { query = query.Where(filter); } foreach (var includeProperty in includeProperties.Split (new char[] { ',' }, StringSplitOptions

Convert Predicate<T> to Expression<Func<T, bool>>

浪尽此生 提交于 2019-12-04 05:49:04
Is possible to convert a Predicate<T> to Expression<Func<T, bool>> in some way? I would like to use the next IQueryable function using the filters of the my ICollectionView: public static System.Linq.IQueryable<TSource> Where<TSource>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<System.Func<TSource, bool>> predicate) Thanks In theory it is possible to convert a delegate 'back' to an expression, because you can request the emitted IL of a delegate, which gives you the information you need to transform it back. However, it's for a reason that neither LINQ to

Create fully dynamic where clause with expression tree and execute on IQueryable

我与影子孤独终老i 提交于 2019-12-04 04:26:01
At point (3) in my code I have defined a query called query1 in which I defined a .Where lambda expression. This query is in some way dynamic but still contains static elements, it always refers to the Type Employee and its (int) property ClientID. Now I very much like to make the refering to the type and its property dynamic, based on the method parameters which by example are shown below point (1). What I tried to so far is making the static part of the query defined under point (3) fully dynamic by replacing it with a more elaborate expression tree as written down in (4), (5) & (6). But

How do I cache an IQueryable object?

大憨熊 提交于 2019-12-04 03:49:19
问题 I've got this method that returns a Linq-to-SQL query for all the rows in a 'UserStatus' table: public IQueryable<BLL.Entity.UserStatus> GetAll() { var query = from e in _SelectDataContext.UserStatus select new BLL.Entity.UserStatus { UserStatusId = e.UserStatusId, Enum = e.Enum, Name = e.Name }; return query; } It's just a look-up table that will hardly ever change so I'd like to cache the results. I can convert it to a List<> and cache that, but I'd prefer to return an IQueryable object as