3

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?

2
  • they have some examples on the same page: github.com/loresoft/EntityFramework.Extended Commented 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? Commented Dec 19, 2012 at 22:43

4 Answers 4

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 });
Sign up to request clarification or add additional context in comments.

1 Comment

Oww my.. I've tried that a million times, yet the Update method never appeared. #facepalm Thanks...
2

You specify Where predicate for Update like so:

context.tblToUpdate
       .Update(entry => condition, entryWithnewValues => new tblToUpdate{});

Comments

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

Comments

-1

The Extensions methods on DbContext are now gone away.

The Extensions methods supported are only on IQueryable

enter image description here

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.