3

NuGet を使用してプロジェクトにEntityFramework.Extended(リンク) を追加しました。今、私は 1 つの問題に直面しています。どうすればそのUpdate機能を私ので使用できdbContextますか?

4

4 に答える 4

8

名前空間をインポートusing EntityFramework.Extensionsして使用しますUpdate(Update メソッドの説明のサンプル):

dbContext.Users.Update(
         u => u.Email.EndsWith(emailDomain),
         u => new User { IsApproved = false, LastActivityDate = DateTime.Now });
于 2012-12-19T22:43:15.320 に答える
2

次のように Update の Where 述語を指定します。

context.tblToUpdate
       .Update(entry => condition, entryWithnewValues => new tblToUpdate{});
于 2012-12-19T22:44:13.760 に答える
0

次のように更新します。

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"});

DbContext を継承し、次のようなパブリック DbSets を持つクラスが必要です。

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; }
    }
}

EntityFramework.Extended を使用するために特別なことは何も必要ありません

于 2012-12-19T22:45:28.097 に答える