Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何 因此,尽管EF不直接支持,但仍然可以使用两种方法之一实现这一点 选项A.手工编写SQL更新语句 这是一种非常简单的方法,不需要任何其他工具/包,也可以异步执行: var sql = "UPDATE TABLE x SET FIELDA = @fiel_C#_Sql_Entity Framework_Sql Update_Entity - Fatal编程技术网

C# 如何 因此,尽管EF不直接支持,但仍然可以使用两种方法之一实现这一点 选项A.手工编写SQL更新语句 这是一种非常简单的方法,不需要任何其他工具/包,也可以异步执行: var sql = "UPDATE TABLE x SET FIELDA = @fiel

C# 如何 因此,尽管EF不直接支持,但仍然可以使用两种方法之一实现这一点 选项A.手工编写SQL更新语句 这是一种非常简单的方法,不需要任何其他工具/包,也可以异步执行: var sql = "UPDATE TABLE x SET FIELDA = @fiel,c#,sql,entity-framework,sql-update,entity,C#,Sql,Entity Framework,Sql Update,Entity,如何 因此,尽管EF不直接支持,但仍然可以使用两种方法之一实现这一点 选项A.手工编写SQL更新语句 这是一种非常简单的方法,不需要任何其他工具/包,也可以异步执行: var sql = "UPDATE TABLE x SET FIELDA = @fieldA WHERE FIELDB = @fieldb"; var parameters = new SqlParameter[] { ..., ... }; int result = db.Database.ExecuteSqlCommand(s

如何

因此,尽管EF不直接支持,但仍然可以使用两种方法之一实现这一点

选项A.手工编写SQL更新语句

这是一种非常简单的方法,不需要任何其他工具/包,也可以异步执行:

var sql = "UPDATE TABLE x SET FIELDA = @fieldA WHERE FIELDB = @fieldb";
var parameters = new SqlParameter[] { ..., ... };
int result = db.Database.ExecuteSqlCommand(sql, parameters);

明显的缺点是,很好地打破了良好的linqy范式,不得不手工编写SQL(可能用于多个目标SQL方言)

选项B。使用EF扩展/实用程序包之一

从一段时间以来,许多开源nuget软件包都提供了对EF的特定扩展。其中许多确实提供了一种很好的“linqy”方式,可以向服务器发出一条updatesql语句。两个例子是:

  • 允许使用以下语句执行批量更新:

    context.Messages.Update( x => x.Read == false && x.SentTo.Id == userID, x => new Message { Read = true }); EFBatchOperation .For(context, context.Messages) .Where(x => x.Read == false && x.SentTo.Id == userID) .Update(x => x.Read, x => x.Read = true); context.Messages.Update( x=>x.Read==false&&x.SentTo.Id==userID, x=>新消息{Read=true});

    也可在

  • 允许使用以下语句执行批量更新:

    context.Messages.Update( x => x.Read == false && x.SentTo.Id == userID, x => new Message { Read = true }); EFBatchOperation .For(context, context.Messages) .Where(x => x.Read == false && x.SentTo.Id == userID) .Update(x => x.Read, x => x.Read = true); EFBatchOperation .For(上下文,context.Messages) .Where(x=>x.Read==false&&x.SentTo.Id==userID) .Update(x=>x.Read,x=>x.Read=true);

    也可在

  • 肯定还有其他软件包和库提供类似的支持