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
445
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
  • 13,219
  • 9
  • 52
  • 62
411
votes
15 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
  • 9,205
  • 11
  • 41
  • 58
276
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
  • 5,114
  • 9
  • 37
  • 41
261
votes
10 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
  • 17,262
  • 11
  • 42
  • 54
249
votes
12 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
  • 56,889
  • 107
  • 278
  • 420
247
votes
3 answers

Linq-to-Entities Join vs GroupJoin

Can someone please explain what a GroupJoin() is? How is it different from a regular Join()? Is it commonly used? Is it only for method syntax? What about query syntax? (A c# code example would be nice)
duyn9uyen
  • 9,585
  • 12
  • 43
  • 54
218
votes
5 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?…
211
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
  • 101,809
  • 122
  • 424
  • 632
210
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,959
  • 6
  • 31
  • 34
190
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
  • 113,627
  • 57
  • 144
  • 179
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
  • 26,321
  • 24
  • 115
  • 201
174
votes
7 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,793
  • 66
  • 176
  • 300
173
votes
15 answers

How to store a list in a column of a database table

So, per Mehrdad's answer to a related question, I get it that a "proper" database table column doesn't store a list. Rather, you should create another table that effectively holds the elements of said list and then link to it directly or through a…
JnBrymn
  • 24,245
  • 28
  • 105
  • 147
169
votes
11 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
  • 71,848
  • 143
  • 435
  • 658
164
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
  • 6,116
  • 14
  • 59
  • 85
1
2 3
99 100