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?
-
they have some examples on the same page: github.com/loresoft/EntityFramework.ExtendedAndrei Drynov– Andrei Drynov2012-12-19 22:40:42 +00:00Commented Dec 19, 2012 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– NucS2012-12-19 22:43:04 +00:00Commented Dec 19, 2012 at 22:43
Add a comment
|
4 Answers
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 });
1 Comment
NucS
Oww my.. I've tried that a million times, yet the Update method never appeared. #facepalm Thanks...
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
Comments
The Extensions methods on DbContext are now gone away.
The Extensions methods supported are only on IQueryable
1 Comment
Sergey Berezovskiy
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