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
20
votes
3 answers

Why use LINQ Join on a simple one-many relationship?

I've been using LINQ to SQL and Entity Framework for a few years and I've always mapped my database relationships to generate the relevant navigation properties. And I always use the navigation properties. Am I missing something? If I have a…
Kirk Broadhurst
  • 27,836
  • 16
  • 104
  • 169
20
votes
3 answers

Include nested entities using LINQ

I'm messing around with LINQ for the first time, and I'm using EF 4.1 code first. I have entities containing nested Lists of other entities, for example: class Release { int ReleaseID { get; set; } string Title { get; set; } …
Will Bithell
  • 267
  • 1
  • 2
  • 10
20
votes
2 answers

Union in entity framework

I have two tables: Vehicles and Workers. Vehicle(Id, Number) Workers(Id, Name, ContractorVehicleNumber) I would like to write lambda query to return all the vehicles and the contractor vehicles. Something like in sql: SELECT Id, Number FROM…
Naor
  • 23,465
  • 48
  • 152
  • 268
20
votes
1 answer

Linq - Left outer join with dot notation

How would I do a left outer join in linq using dot notation? Here's the query expression: var query = from u in db.Users join d in db.Defects on u.userID equals d.userID into defectsGroup from d in…
Adam Rackis
  • 82,527
  • 56
  • 270
  • 393
20
votes
2 answers

EF - DistinctBy on an IQueryable?

Say I have this where I want to get every person in group 42, but I want to get an IQueryable of each unique first name in the database (PS - I know I can call AsQueryable() after the Select but that's not what I'm interested in doing - I…
Pugz
  • 939
  • 3
  • 11
  • 25
20
votes
7 answers

Proper way to delete record in LINQ to Entities

I just have a very simple situation where all I need is to delete record using Linq2Entities. I tried to do some research and still can't figure out the right way to do it. Here's my simple…
Harold Javier
  • 887
  • 2
  • 7
  • 16
20
votes
2 answers

Dynamic where clause (OR) in Linq to Entities

In the post here I learned how to build a dynamic query using the deferred execution of Linq. But the query is actually using an AND concatenation of the WHERE condition. How can I achieve the same query but with an OR logic? Due to the Flags…
20
votes
1 answer

How can a LINQ join select only the first record?

I wish to select only the first record from the 'CustomerSubOwners' table in join query below and wondered what was the best way to achieve this in LINQ. var result= (from t1 in db.Cases from t2 in db.CustomerSubOwners …
Nick
  • 5,844
  • 11
  • 52
  • 98
20
votes
2 answers

using Linq with multiple where conditions

I have a class representing a table on database that is defined: public class MyClass{ public int MyClassId{get;set;} public string Name{get;set;} public string LastNamw{get;set;} public DateTime From{get;set;} public DateTime…
cpoDesign
  • 8,953
  • 13
  • 62
  • 106
19
votes
1 answer

LINQ to Entities Group By expression gives 'Anonymous type projection initializer should be simple name or member access expression'

I am getting the above mentioned error with this expression: var aggregate = from t in entities.TraceLines join m in entities.MethodNames.Where("it.Name LIKE @searchTerm", new ObjectParameter("searchTerm", searchTerm)) on t.MethodHash equals…
esac
  • 24,099
  • 38
  • 122
  • 179
19
votes
1 answer

"Select NOT IN" clause in Linq to Entities

Is there a way to use the "NOT IN (select XXX...)" clause in Linq to Entities? All the questions I found were regarding a list of objects (IN (1,2,3)) but I want to generate a query with the following syntax: select * from table1 where field1 not…
lnetanel
  • 1,118
  • 3
  • 13
  • 28
19
votes
1 answer

GroupBy with elementSelector and resultSelector

The Enumerable.GroupBy and Queryable.GroupBy extensions have 8 overloads. Two of them (for Enumerable.GroupBy) are: // (a) IEnumerable GroupBy( this IEnumerable source, Func
Slauma
  • 175,098
  • 59
  • 401
  • 420
19
votes
6 answers

Could not load file or assembly ':This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded

I Hvea 3 projects in my solution: BL, DL and the UI. All three projectshave a target framework of >NET 4; I have double-checked this by looking at the property page for each project. I am receiving the following error message when I try run the…
Susan
  • 1,822
  • 8
  • 47
  • 69
18
votes
3 answers

Linq to Entities (EF 4.1): How to do a SQL LIKE with a wildcard in the middle ( '%term%term%')?

I want to search for this: Post Cereal and get this: Post Honey Nut Cereal where the wild cards would be the spaces. I know I could do a SPLIT and a series of ANDs and Contains() and translation to a Linq Expression for each term as a…
Zachary Scott
  • 20,968
  • 35
  • 123
  • 205
18
votes
2 answers

How can I get the count in linq?

I have table called products with columns: productid , productname, productprice categoryid My problem is I want to get the number of products depending on product name along with details. I want to show the data in DataGridView. How can I know…
Glory Raj
  • 17,397
  • 27
  • 100
  • 203