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
149
votes
2 answers

New transaction is not allowed because there are other threads running in the session LINQ To Entity

Any ideas on why this could be breaking? foreach (var p in pp) { ProjectFiles projectFile = (ProjectFiles)p; projectFile.Status = Constants.ProjectFiles_ERROR; projectFile.DateLastUpdated = DateTime.Now; context.SaveChanges(); } I…
Nick LaMarca
  • 8,076
  • 31
  • 93
  • 152
147
votes
14 answers

Only parameterless constructors and initializers are supported in LINQ to Entities

I have this error in this linq expression : var naleznosci = (from nalTmp in db.Naleznosci where nalTmp.idDziecko == idDziec select new Payments ( …
netmajor
  • 6,507
  • 14
  • 68
  • 100
139
votes
5 answers

LINQ to Entities does not recognize the method

I'm getting the following error when trying to do a linq query: LINQ to Entities does not recognize the method 'Boolean IsCharityMatching(System.String, System.String)' method, and this method cannot be translated into a store expression. I've…
annelie
  • 2,569
  • 6
  • 25
  • 39
134
votes
6 answers

Entity Framework 4 Single() vs First() vs FirstOrDefault()

I'm having a devil of a time finding a comparison of the different ways to query for a single item, and when to use each. Does anyone have a link that compares all these, or a quick explanation as to why you would use one over the other? Are there…
asfsadf
  • 3,822
  • 7
  • 31
  • 41
130
votes
8 answers

LINQ to Entities case sensitive comparison

This isn't a case-sensitive comparison in LINQ to Entities: Thingies.First(t => t.Name == "ThingamaBob"); How can I achieve case sensitive comparison with LINQ to Entities?
Ronnie Overby
  • 45,287
  • 73
  • 267
  • 346
124
votes
8 answers

Best way to check if object exists in Entity Framework?

What is the best way to check if an object exists in the database from a performance point of view? I'm using Entity Framework 1.0 (ASP.NET 3.5 SP1).
Freddy
  • 1,705
  • 3
  • 13
  • 16
124
votes
5 answers

SQL to Entity Framework Count Group-By

I need to translate this SQL statement to a Linq-Entity query... SELECT name, count(name) FROM people GROUP by name
fefwfefefwfwe
  • 1,505
  • 2
  • 11
  • 19
120
votes
15 answers

How to compare only date components from DateTime in EF?

I am having two date values, one already stored in the database and the other selected by the user using DatePicker. The use case is to search for a particular date from the database. The value previously entered in the database always has time…
pencilslate
  • 12,958
  • 18
  • 58
  • 73
116
votes
9 answers

Like Operator in Entity Framework?

We're trying to implement the "LIKE" operator in Entity Framework for our entities with string fields, but it doesn't appear to be supported. Has anyone else tried to do something like this? This blog post summarizes the issue we're having. We…
brien
  • 4,400
  • 4
  • 30
  • 32
111
votes
9 answers

The specified type member 'Date' is not supported in LINQ to Entities Exception

I got a exception while implementing the following statements. DateTime result; if (!DateTime.TryParse(rule.data, out result)) return jobdescriptions; if (result < new DateTime(1754, 1, 1)) // sql can't handle dates before 1-1-1753 …
nebula
  • 3,932
  • 13
  • 53
  • 82
109
votes
10 answers

C# - code to order by a property using the property name as a string

What's the simplest way to code against a property in C# when I have the property name as a string? For example, I want to allow the user to order some search results by a property of their choice (using LINQ). They will choose the "order by"…
Jeremy
  • 9,023
  • 20
  • 57
  • 69
109
votes
9 answers

The type or namespace name 'Objects' does not exist in the namespace 'System.Data'

I am using entities, C# and SQL Server to create an n-tier app. I am creating some base classes common to all my DAL components. In this base class, i want to handle the connection state of the ObjectContext base class inherited by entities…
pencilslate
  • 12,958
  • 18
  • 58
  • 73
106
votes
7 answers

Entity framework left join

How do I change this query so it returns all u.usergroups? from u in usergroups from p in u.UsergroupPrices select new UsergroupPricesList { UsergroupID = u.UsergroupID, UsergroupName = u.UsergroupName, Price = p.Price };
Lasse Edsvik
  • 9,070
  • 16
  • 73
  • 109
91
votes
1 answer

Method cannot be translated into a store expression

I saw this code work with LINQ to SQL but when I use Entity Framework, it throws this error: LINQ to Entities does not recognize the method 'System.Linq.IQueryable'1[MyProject.Models.CommunityFeatures] GetCommunityFeatures()' method, and this…
Shawn Mclean
  • 56,733
  • 95
  • 279
  • 406
91
votes
3 answers

LINQ to Entities does not recognize the method 'System.String Format(System.String, System.Object, System.Object)'

I have this linq query: private void GetReceivedInvoiceTasks(User user, List tasks) { var areaIds = user.Areas.Select(x => x.AreaId).ToArray(); var taskList = from i in _db.Invoices join a in _db.Areas on i.AreaId…
AnonyMouse
  • 18,108
  • 26
  • 79
  • 131