简体   繁体   English

批量插入/更新的实体框架替代方法

[英]Entity Framework Alternative Method for Bulk Inserting/Updating

So for some background I'm inserting/updating large numbers > 100,000s of objects into a table. 因此,对于某些背景,我正在向表中插入/更新大量> 100,000s的对象。 The table has a one to one relation with another table, as well as having aa many to one relation ship with another, which all obviously need to be preserved. 该表与另一张表具有一对一关系,并且与另一张表具有多对一关系,所有这些显然都需要保留。 Something of note is that most of the need is for UPDATING, generally we are adding information the first time we find it, and then continuously update it based on changes. 需要注意的是,大多数需求都是更新,通常我们是在第一次发现信息时就添加信息,然后根据更改不断对其进行更新。 I've been trying to do my due diligence before asking, so I've looked at many other sources on the topic, and have proceeded to disable things like change tracking, batching adds then using a new context, etc, but it's still not really where I'd like for (or think) it to be. 在进行询问之前,我一直在进行尽职调查,因此我查看了该主题上的许多其他资源,并尝试禁用更改跟踪,添加批处理然后使用新上下文等功能,但仍然没有确实是我想要(或认为)它的位置。

So with that said I wanted to change to using Bulk Insert, and was wondering if there are any good extension libraries that are generally accepted/reliable/etc, or can anyone give any advice on how to proceed/recommend resources on implementing BulkInsert from entity framework objects. 因此,我想转而使用大容量插入,并且想知道是否有任何公认的/可靠的等好的扩展库,或者有人可以就如何继续/推荐从实体实现BulkInsert的资源给出任何建议吗?框架对象。 Some concerns I have is updating as opposed to inserting and whether that is something BulkInsert can support, as well as retaining relations and what Bulk Insert does in that regard. 我要更新的一些问题是插入而不是插入,BulkInsert是否可以支持该问题,以及保留关系以及BulkInsert在这方面做了什么。

As a final note I saw a recommendation somewhere to bulk insert all of the entries to a temp table, then use that to merge, and then drop the temp table. 作为最后的注释,我看到了一个建议,该建议将所有条目批量插入到临时表中,然后使用它进行合并,然后删除该临时表。 That seemed promising as it would handle both update and insert. 这似乎很有希望,因为它将同时处理更新和插入。

the solutions is use many times the same context each cycle, and save at the same time. 解决方案是每个循环多次使用相同的上下文,并同时保存。

Visit this post, It helped me a lot Fastest Way inserting entity 访问这篇文章,它对我最快的方式插入实体很有帮助

I hope it helps you 希望对您有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM