在Entity Frameowork中执行批量更新/删除 [英] Perform bulk Update/Delete in Entity Frameowork

查看:111
本文介绍了在Entity Frameowork中执行批量更新/删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< re lang =sql>我想在不加载数据库的情况下执行批量更新/删除,更新每个实体,然后将其保存回数据库。



在Google上有许多人有很多答案,其中大多数是:



+直接使用SQL语句(弱点是当我更改Model类名时,我必须更改所有SQL语句甚至外键)



+使用EntityFramework.Exnteded(我无法更新导航属性)



所以,到目前为止(当我发布这个话题时)是EF 6.0发布/新方式是否支持我们批量更新/删除?

<re lang="sql">I want to perform bulk Update/Delete without load enties from database, update each entity then save it back to database.

On Google many peoples with many answers, Most of them are:

+ Use directly SQL Statement ( The weakness is when I change the Model class name, i have to change all SQL Statements even the Foreign Key )

+ Use EntityFramework.Exnteded (I can't update Navigation property)

So, Up to now ( At the time I post this topic ) Is is EF 6.0 released/new manners support us to bulk Update/Delete ?

推荐答案

如果您经常更改模型名称,那么只需简单搜索&替换为文本编辑器不再适合,那么您可以尝试在Visual Studio中使用代码片段。

它们允许您构造任何文本文档,定义一些必须被替换的标记,您可以在调用代码段时输入的值。



您可以在此处找到有关代码片段的更多信息:

< a href =http://msdn.microsoft.com/en-us/library/ms165392%28v=VS.80%29.aspx>创建和使用IntelliSense代码段 [ ^ ]

演练:创建代码段 [ ^ ]
If you are changing your model names so often that a simple search & replace with a text editor does not suit anymore, then you could try to go for code-snippets in Visual Studio.
They allow you to construct any text document, defining some tokens that are bound to be replaced, by values that you can input when you invoke the snippet.

You can find some more info on code-snippets here:
Creating and Using IntelliSense Code Snippets[^]
Walkthrough: Creating a Code Snippet[^]


这篇关于在Entity Frameowork中执行批量更新/删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆