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

6675 questions
434
votes
5 answers

Entity Framework VS LINQ to SQL VS ADO.NET with stored procedures?

How would you rate each of them in terms of: Performance Speed of development Neat, intuitive, maintainable code Flexibility Overall I like my SQL and so have always been a die-hard fan of ADO.NET and stored procedures but I recently had a play…
BritishDeveloper
  • 12,481
  • 7
  • 49
  • 59
402
votes
14 answers

How to do SQL Like % in Linq?

I have a procedure in SQL that I am trying to turn into Linq: SELECT O.Id, O.Name as Organization FROM Organizations O JOIN OrganizationsHierarchy OH ON O.Id=OH.OrganizationsId where OH.Hierarchy like '%/12/%' The line I am most concerned with…
Matt Dell
  • 8,298
  • 8
  • 35
  • 55
260
votes
10 answers

How to use DbContext.Database.SqlQuery(sql, params) with stored procedure? EF Code First CTP5

I have a stored procedure that has three parameters and I've been trying to use the following to return the results: context.Database.SqlQuery("mySpName", param1, param2, param3); At first I tried using SqlParameter objects as the…
electricsheep
  • 4,834
  • 8
  • 35
  • 41
239
votes
8 answers

Linq to Entities - SQL "IN" clause

In T-SQL you could have a query like: SELECT * FROM Users WHERE User_Rights IN ("Admin", "User", "Limited") How would you replicate that in a LINQ to Entities query? Is it even possible?
StevenMcD
  • 16,572
  • 11
  • 40
  • 53
207
votes
3 answers

Linq to Entities join vs groupjoin

I have web searched but I still cant find a simple answer. Can someone please explain (in simple English) what a GroupJoin is? How is it different from a regular inner Join? Is it commonly used? Is it only for method syntax? What about query syntax?…
duyn9uyen
  • 7,733
  • 12
  • 36
  • 47
205
votes
15 answers

Problem with converting int to string in Linq to entities

var items = from c in contacts select new ListItem { Value = c.ContactId, //Cannot implicitly convert type 'int' (ContactId) to 'string' (Value). Text = c.Name }; var items = from c…
Shimmy Weitzhandler
  • 92,920
  • 119
  • 388
  • 596
201
votes
10 answers

"A lambda expression with a statement body cannot be converted to an expression tree"

In using the EntityFramework, I get the error "A lambda expression with a statement body cannot be converted to an expression tree" when trying to compile the following code: Obj[] myArray = objects.Select(o => { var someLocalVar = o.someVar; …
pistacchio
  • 50,394
  • 95
  • 256
  • 391
198
votes
8 answers

The cast to value type 'Int32' failed because the materialized value is null

I have the following code. I'm getting error: "The cast to value type 'Int32' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type." when CreditHistory table has no…
zosim
  • 2,809
  • 6
  • 29
  • 34
193
votes
4 answers

What's the difference(s) between .ToList(), .AsEnumerable(), AsQueryable()?

I know some differences of LINQ to Entities and LINQ to Objects which the first implements IQueryable and the second implements IEnumerable and my question scope is within EF 5. My question is what's the technical difference(s) of those 3 methods?…
189
votes
9 answers

Learning about LINQ

Overview One of the things I've asked a lot about on this site is LINQ. The questions I've asked have been wide and varied and often don't have much context behind them. So in an attempt to consolidate the knowledge I've acquired on Linq I'm posting…
lomaxx
  • 104,787
  • 56
  • 140
  • 177
183
votes
12 answers

Entity Framework 4 / POCO - Where to start?

I've been programming for a while and have used LINQ-To-SQL and LINQ-To-Entities before (although when using entities it has been on a Entity/Table 1-1 relationship - ie not much different than L2SQL) I've been doing a lot of reading about Inversion…
Basic
  • 25,223
  • 23
  • 108
  • 188
157
votes
5 answers

String.IsNullOrWhiteSpace in LINQ Expression

I have the following code: return this.ObjectContext.BranchCostDetails.Where( b => b.TarrifId == tariffId && b.Diameter == diameter || (b.TarrifId==tariffId && !string.IsNullOrWhiteSpace(b.Diameter)) || (!b.TarrifId.HasValue) &&…
Hossein Moradinia
  • 5,696
  • 14
  • 54
  • 85
150
votes
5 answers

How to get first record in each group using Linq

Considering the following records: Id F1 F2 F3 ------------------------------------------------- 1 Nima 1990 10 2 Nima 1990 11 3 Nima …
Arian
  • 12,864
  • 60
  • 165
  • 271
149
votes
10 answers

The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties

Using this code in Entity Framework I receive the following error. I need to get all the rows for a specific date, DateTimeStart is of type DataType in this format 2013-01-30 12:00:00.000 Code: var eventsCustom =…
GibboK
  • 64,078
  • 128
  • 380
  • 620
147
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
  • 7,512
  • 28
  • 86
  • 145
1
2 3
99 100