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
45
votes
11 answers

Updating your edmx to reflect changes made in your db (.net linq-to-entities)

So I have my edmx made. Then I change my database a little bit, changing a column to from being a NOT NULL to allowing NULL. I go into my edmx, right click and choose "Update Model from Database" Now I go into my program and it hasnt actually…
Stuck In Baghdad
  • 629
  • 2
  • 9
  • 10
45
votes
2 answers

What is the purpose of .edmx files?

What is the purpose of .edmx files? Reading the CSDL, SSDL, and MSL specifications, it looks to me like .edmx files are used only at design time. Are we meant to distribute it with the other edmx? It seems like we need to distribute the .ssdl…
43
votes
4 answers

How to move from Linq 2 SQL to Linq 2 Entities?

I'd like to start a reference for people who want to move from linq2sql to linq2entities and the ADO.net Entity Framework (in here called L2E). I don't want to discuss which of these two is better. I just want to create a list of differences between…
Sam
  • 28,421
  • 49
  • 167
  • 247
43
votes
8 answers

Conditional Include() in Entity Framework

I have seen a few answers to similar questions, however I cannot seem to work out how to apply the answer to my issue. var allposts = _context.Posts .Include(p => p.Comments) .Include(aa => aa.Attachments) …
43
votes
4 answers

How to avoid Query Plan re-compilation when using IEnumerable.Contains in Entity Framework LINQ queries?

I have the following LINQ query executed using Entity Framework (v6.1.1): private IList GetFullCustomers(IEnumerable customersIds) { IQueryable fullCustomerQuery = GetFullQuery(); return fullCustomerQuery.Where(c =>…
t3z
  • 1,737
  • 12
  • 14
41
votes
4 answers

LINQ to Entities how to update a record

Okay, so I'm new to both EF and LINQ. I have figured out how to INSERT and DELETE but for some reason UPDATE seems to escape my grasp. Here is a sample of my code: EntityDB dataBase = new EntityDB(); Customer c = new Customer { Name = "Test", …
CatDadCode
  • 58,507
  • 61
  • 212
  • 318
41
votes
5 answers

How do I eliminate Error 3002?

Say I have the following table definitions in SQL Server 2008: CREATE TABLE Person (PersonId INT IDENTITY NOT NULL PRIMARY KEY, Name VARCHAR(50) NOT NULL, ManyMoreIrrelevantColumns VARCHAR(MAX) NOT NULL) CREATE TABLE Model (ModelId INT IDENTITY…
Andrew
  • 14,325
  • 4
  • 43
  • 64
41
votes
5 answers

LINQ to Entities does not recognize the method 'System.TimeSpan Subtract(System.DateTime)' method

I try to select records in database in 60 days 30 days 20 days differents in current date. Please see this query in below. var uploads = ( from files in _fileuploadRepository.Table join product in…
Ragesh P Raju
  • 3,879
  • 14
  • 101
  • 136
40
votes
12 answers

Linq to Entities, random order

How do i return matching entities in a random order? Just to be clear this is Entity Framework stuff and LINQ to Entities. (air code) IEnumerable results = from en in context.MyEntity where en.type ==…
NikolaiDante
  • 18,469
  • 14
  • 77
  • 117
40
votes
7 answers

How do I delete an object from an Entity Framework model without first loading it?

I am quite sure I've seen the answer to this question somewhere, but as I couldn't find it with a couple of searches on SO or google, I ask it again anyway... In Entity Framework, the only way to delete a data object seems to be MyEntityModel ent =…
Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402
40
votes
13 answers

Group by Weeks in LINQ to Entities

I have an application that allows users to enter time they spend working, and I'm trying to get some good reporting built for this which leverages LINQ to Entities. Because each TrackedTime has a TargetDate which is just the "Date" portion of a…
StriplingWarrior
  • 151,543
  • 27
  • 246
  • 315
37
votes
2 answers

C# 7.0 Value Tuple compile error?

When I am trying to compile the following code: var post = iPostService.GetAll().Select(x => (x.Title, x.Author)); I get the compiler error: 'An expression tree may not contain a tuple literal.' So I also tried this: var post =…
Tan Sang
  • 1,897
  • 1
  • 16
  • 28
37
votes
5 answers

Convert anonymous type to new C# 7 tuple type

The new version of C# is there, with the useful new feature Tuple Types: public IQueryable Query(); public (int id, string name) GetSomeInfo() { var obj = Query() .Select(o => new { id = o.Id, …
37
votes
2 answers

Howto use predicates in LINQ to Entities for Entity Framework objects

I'm using LINQ to Entities for Entity Framework objects in my Data Access Layer. My goal is to filter as much as I can from the database, without applying filtering logic to in-memory results. For that purpose Business Logic Layer passes a…
bairog
  • 3,143
  • 6
  • 36
  • 54
36
votes
1 answer

LINQ to Entities does not recognize the method 'System.DateTime GetValueOrDefault()'

Struggling with very simple code that isn't working where similar code is working in other classes. It won't compile if I remove GetValueOrDefault(). Also I am using System.Linq. I'm getting this runtime error: LINQ to Entities does not recognize…
jfk
  • 361
  • 1
  • 3
  • 4