linq-to-entities

Can we control LINQ expression order with Skip(), Take() and OrderBy()

北城以北 提交于 2019-12-20 19:41:37
问题 I'm using LINQ to Entities to display paged results. But I'm having issues with the combination of Skip() , Take() and OrderBy() calls. Everything works fine, except that OrderBy() is assigned too late. It's executed after result set has been cut down by Skip() and Take() . So each page of results has items in order. But ordering is done on a page handful of data instead of ordering of the whole set and then limiting those records with Skip() and Take() . How do I set precedence with these

Proper use of “Using” statement for datacontext

喜夏-厌秋 提交于 2019-12-20 15:08:31
问题 I’m using Linq to Entities and lately, I found that a lot of folks recommending wrapping the datacontext in a using statement like this: Using(DataContext db = new DataContext) { var xx = db.customers; } This makes sense. However, I’m not sure how to incorporate this practice in my model. For example: I have an interface (let’s call it customer) and it is implemented by a repository like this: namespace Models { public class rCustomer : iCustomer { readonly DataContext db = new DataContext();

Join between in memory collection and EntityFramework

拈花ヽ惹草 提交于 2019-12-20 11:54:10
问题 Is there any mechanism for doing a JOIN between an in-memory collection and entity framework while preserving the order. What I am trying is var itemsToAdd = myInMemoryList.Join(efRepo.All(), listitem => listitem.RECORD_NUMBER, efRepoItem => efRepoItem.RECORD_NUMBER, (left, right) => right); which gives me the rather curiously titled "This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code." error. Now of course I can do this iteratively

Casting to a derived type in a LINQ to Entities query with Table Per Hierarchy inheritance

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-20 11:19:12
问题 I have a LINQ to entities model with Table Per Hierarchy inheritance. I have a query over the base type, and I want to do specific type-dependent logic. For example: IQueryable<BaseType> base = ... // this works fine var result = base.Select(b => b is DerivedType1 ? 1 : 2).ToList(); // this doesn't compile to SQL var result2 = base.Select(b => b is DerivedType1 ? ((DerivedType1)b).DerivedProperty : null).ToList(); Is there any way to do something like this without processing IQueryables of

Linq for entities Framework 4.1 tutorials/ebooks links [closed]

假如想象 提交于 2019-12-20 10:57:35
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Is there any good LINQ tutorial for Entities Framework 4.1 Code First for medium to complex level? Please suggest books as well. 回答1: For Linq-to-entities you can check MSDN: Syntax examples Linq-to-entities Sources for EFv4.1 code first are: ADO.NET team blog Morteza Manavi's blog Julia Lerman's blog Stack

what are 'EdmFunctions' for?

≡放荡痞女 提交于 2019-12-20 06:29:55
问题 i saw the System.Data.Common.CommandTrees.ExpressionBuilder.EdmFunctions static class accidently, that contains a set of extension methods on System.Data.Common.CommandTrees.DbExpression , like AddDays, Concat,.... which bring back System.Data.Common.CommandTrees.DbFunctionExpression as return type, this static methods if needs to an argument, they only accept a System.Data.Common.CommandTrees.DbExpression type, in addition i look over the System.Data.Common.CommandTrees.DbExpression and i

Entity Navigation Property IQueryable cannot be translated into a store expression

我只是一个虾纸丫 提交于 2019-12-20 06:00:24
问题 im using Entity Framework designer first and I need to create custom Model Objects starting from the db objects. I don't want to use IEnumerable cause it will query too many fields. The goal is to remove the inner select within this function: using (var db = new dbEntities()) { var departments= db.departments .Include(p => p.employee) .Where(...) .Select(p => new CustomDepartmentModel() { ID = p.ID, Employees = p.employee .Select(q => new CustomEmployeeModel() { ID = q.ID, Name= q.Name })

Chaining / building LINQ query with an OR instead of AND

落爺英雄遲暮 提交于 2019-12-20 05:39:18
问题 Edited to be clearer. If for example I have this IQueryable: DateTime theDate = new DateTime(2015, 09, 30); var query = from org in Organisations where org.DisableOrganisation == false && org.DisableReports == false select new { OrganisationId = org.OrganisationId }; and later in the method I want to add an OR to it, e.g. // Check to see if the date is the last day of the month. if (theDate.AddDays(1).Day == 1) { // The following statement introduces an AND but I want to make this an OR.

How can I execute an Oracle function from within a LINQ expression in Entity Framework 4?

最后都变了- 提交于 2019-12-20 04:59:08
问题 I am using Visual Studio 2010, C#, Entity Framework 4 and Oracle 10g. I need to be able to return the result of a database function as a scalar property of an anonymous type. My Oracle schema has two tables, PARENT and CHILD, and a function FNC_ADD. I have created an entity model using the Visual Studio ADO.NET Entity Data Model template, including both tables and the function. The StorageModels section of my .edmx file looks like this: <!-- SSDL content --> <edmx:StorageModels> <Schema

Linq-to-Entities: LEFT OUTER JOIN with WHERE clause, calculation and projection

不打扰是莪最后的温柔 提交于 2019-12-20 04:52:19
问题 I'm having a very difficult time figuring out how to translate a simple SQL LEFT OUTER JOIN on multiple columns and a where clause into a working Linq-to-Entities query. There are only two tables. I need values for all rows from Table1, regardless of matches in Table2, but joining multiple columns is proving difficult. I also need to do a simple calculation in the query, but can't find that either. The query in SQL would look like this: select t1.tableid1, t1.tableid2, t1.fieldvalue1, t2