Questions tagged [linq-to-entities]

This tag is for questions about LINQ to Entities, which means LINQ queries using the ADO.NET Entity Framework. Note that this is different than LINQ to SQL or other LINQ providers.

This tag is for questions about LINQ to Entities, which means LINQ queries using the ADO.NET Entity Framework. Note that this is different than LINQ to SQL or other LINQ providers.

Related Links

6860 questions
3
votes
1 answer

Difference between "select new" and "Select(a => new"

please consider this 2 queries and their result: var result = ent.tblCustomGroupBies .GroupBy(a => groupA.Contains(a.Group.Value) ? "A" : groupB.Contains(a.Group.Value) ? "B" : "N/a") …
Arian
  • 12,793
  • 66
  • 176
  • 300
3
votes
2 answers

How to update an existing object's properties using LINQ to Entities?

LINQ to Entities allows this: context.User.Select(u => new Person { Name = u.Name, Parent = u.Parent.Name }); I need only two properties of a big User table and I get them using the Select method to create a Person object so I can do some…
Şafak Gür
  • 7,045
  • 5
  • 59
  • 96
3
votes
2 answers

Equality comparison fails between C# datetime and SQL datetime

I am trying to do an equality comparison between a C# datetime and a SQL datetime, which appears to fail due to the precision in which those values are stored. So say I have a really simple SQL table, with these fields: ID (PK, int, not null) -…
MadHenchbot
  • 1,306
  • 2
  • 13
  • 27
3
votes
1 answer

Entity framework. Quering parent entity with subclass property loaded

There is a simple domain.. public abstract class UserComment { public string Text { get; set; } } public class BlogComment : UserComment { public Blog Blog { get; set; } } public class PhotoComment : UserComment { public Photo Photo {…
Jekas
  • 578
  • 4
  • 15
3
votes
2 answers

What is the recommended practice for sharing similar linq to entities expression logic in different repositories

When using the repository pattern , sometimes you have the same logic that appears in different repositories.In the example below GetTempEmployees() in EmployeeRepository and GetCompaniesWithTemps() in CompanyRepository have the same expressions…
kwiri
  • 1,399
  • 2
  • 15
  • 22
3
votes
1 answer

LINQ to Entities does not recognize the method 'System.String[] ToArray[String]

i have nearly 1 million data, which i definitely don't want to query all of them to memory and then group them, so i tried this, but linq2Entity does not recognize string.join(), IEnumerable.toList(), or same things var capaHrs = ( …
Scott 混合理论
  • 2,263
  • 8
  • 34
  • 59
3
votes
4 answers

Breaking LINQ to Entities into multiple parts

I had the following code query = query.Where(device => GetDeviceDistanceFromGeocode(geocode, device) <= distanceMetres); private static double GetDeviceDistanceFromGeocode(Geocode geocode, Device device) { return Math.Pow( …
Neil
  • 5,179
  • 8
  • 48
  • 87
3
votes
2 answers

Why does Entity Framework generate slow overengineered SQL?

I have this code: DbSet table = ...// stored reference var items = from n in table where n.Name.ToUpper().Contains(searchString.ToUpper().Trim()) select n; WriteToLog( items.ToString() ); The last line outputs…
sharptooth
  • 167,383
  • 100
  • 513
  • 979
3
votes
2 answers

LinqToEntities use less than (<) within LEFT OUTER JOIN

I'm working with a colleague and we're trying to reproduce the following SQL Query using LinqToEntities (Entity Framework v4.0) SELECT t1.* FROM [dbo].LocaleStringResource AS t1 LEFT OUTER JOIN [dbo].LocaleStringResource AS t2 ON…
Lloyd Holman
  • 974
  • 6
  • 7
3
votes
4 answers

Reuseable ObjectContext or new ObjectContext for each set of operations?

I'm new to the Entities Framework, and am just starting to play around with it in my free time. One of the major questions I have is regarding how to handle ObjectContexts. Which is generally preferred/recommended of these: This public class…
Mark Carpenter
  • 17,445
  • 22
  • 96
  • 149
3
votes
2 answers

Restrict EF query to a base type with TPT inheritance

Consider the following entity framework model with TPT inheritance. DB Tables: Person (PersonID, Name) Student (PersonID, Grade) EF Entities: Person (PersonID, Name) Student (Grade) : inherits from Person Now when you're trying to select a person…
Grief Coder
  • 6,508
  • 9
  • 38
  • 51
3
votes
5 answers

LINQ to Entities does not recognize the method 'System.String ToString(Int32)' method, and this method cannot be translated into a store expression

Using MVC3 VS2010 and SQL Server 2008 Express I am trying to filter based on two SQL Server tables and display the result. One table is clients table and the other is agent. They have in common ClientAgentID in the clients table and ID in the…
WillNZ
  • 765
  • 5
  • 13
  • 38
3
votes
4 answers

Except() on EntityCollection vs List

Using EntityFramework 4. I have an EntityCollection currentEntities with ~500k entities and a List importedEntities also with ~500k records. I want to have the list of all records occuring in currentEntities which don't exist…
Dejan Janjušević
  • 3,181
  • 4
  • 41
  • 67
3
votes
1 answer

Linq statement with mutiple OrderBy clauses not working

I have a local collection that I am trying to sort with Linq but the returned in memory collection still remains sorted by the numeric ID column FailureID. Any idea why these OrderBy clauses are not taking effect? Object Public Class…
Phil Murray
  • 6,396
  • 9
  • 45
  • 95
3
votes
2 answers

Instruct LINQ to Entities to Generate Oracle Compatible SQL

I have a linq to entities query (EF 4.3) var query = from item in db.TableTest select item.VAL; which translates to this SQL statement SELECT "Extent1"."VAL" AS "VAL" FROM "dbo"."TEST_TABLE" "Extent1" The database is Oracle. When I…