I've added EntityFramework.Extended
(link) to my project using NuGet.
Now I'm facing one single problem; how can I use it's Update
function with my dbContext
?
Asked
Active
Viewed 4,368 times
3

NucS
- 619
- 8
- 21
-
they have some examples on the same page: https://github.com/loresoft/EntityFramework.Extended – Andrei Drynov Dec 19 '12 at 22:40
-
I've already seen that, but this does not help me in any way to understand how can I add/extend the methods to the dbContext as they did. Am I missing anything or I lack some knowledge? – NucS Dec 19 '12 at 22:43
4 Answers
8
Import namespace using EntityFramework.Extensions
and use Update
(sample from Update method description):
dbContext.Users.Update(
u => u.Email.EndsWith(emailDomain),
u => new User { IsApproved = false, LastActivityDate = DateTime.Now });

Sergey Berezovskiy
- 232,247
- 41
- 429
- 459
-
Oww my.. I've tried that a million times, yet the Update method never appeared. #facepalm Thanks... – NucS Dec 19 '12 at 22:47
2
You specify Where predicate for Update like so:
context.tblToUpdate
.Update(entry => condition, entryWithnewValues => new tblToUpdate{});

Evgeny Lukashevich
- 1,500
- 14
- 26
0
Update with:
YourDbContext context=new YourDbContext();
//update all tasks with status of 1 to status of 2
context.YourModels.Update(
t => t.StatusId == 1,
t2 => new Task {StatusId = 2});
//example of using an IQueryable as the filter for the update
var yourmodel = context.YourModels.Where(u => u.FirstName == "firstname");
context.YourModels.Update(yourmodel , u => new YourModel {FirstName = "newfirstname"});
You should have a class that inherits DbContext and has public DbSets like:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Entity;
namespace YourNamespace.Models
{
public class YourDBContext: DbContext
{
public DbSet<YourModel> YourModels { get; set; }
}
}
Nothing special is required for using EntityFramework.Extended

Kaizen Programmer
- 3,798
- 1
- 14
- 30
-1
The Extensions methods on DbContext are now gone away.
The Extensions methods supported are only on IQueryable

Marco Staffoli
- 2,475
- 2
- 27
- 29
-
This answer is not related to legacy *EntityFramework.Extended* library. It does not solve the problem described in the question. It might be a comment to the question. And why do you think that legacy extensions supported DbContext? `dbContext.Users.Update` is not a DbContext extension – Sergey Berezovskiy Jul 31 '17 at 10:31