Why is inserting entities in EF 4.1 so slow compared to ObjectContext?

Basically, I insert 35000 objects within one transaction: using(var uow = new MyContext()){ for(int i = 1; i < 35000; i++) { var o = new MyObject()...; uow.MySet.Add(o); } uow.SaveChanges(); } This takes forever! If I use the underlying ObjectContex t (by using IObjectAdapter ), it's still slow but takes around 20s. It looks like DbSet<> is doing some linear searc

与ObjectContext相比,为什么在EF 4.1中插入实体很慢?

基本上,我在一个事务中插入35000个对象: using(var uow = new MyContext()){ for(int i = 1; i < 35000; i++) { var o = new MyObject()...; uow.MySet.Add(o); } uow.SaveChanges(); } 这需要永远! 如果我使用底层ObjectContex t(通过使用IObjectAdapter ),它仍然很慢,但大约需要20 IObjectAdapter 。 它看起来像DbSet<>正在做一些线性搜索,这需要平方时间... 任何人看到这个问题?

How can I get Id of inserted entity without saveChanges in Entity framework?

This question already has an answer here: Entity Framework - retrieve ID before 'SaveChanges' inside a transaction 3 answers //MyClass has Id as property, this is set by the DB server var myObject = new MyClass { NotIdProp = someVal; } int idAfterInsert; //or string if using GUID for Id //transaction and then dispose DB context using (var db = new MyContext()) { //add the entity

如何在Entity框架中获取没有saveChanges的插入实体的Id?

这个问题在这里已经有了答案: 实体框架 - 在'SaveChanges'之前检索事务处理3个答案 //MyClass has Id as property, this is set by the DB server var myObject = new MyClass { NotIdProp = someVal; } int idAfterInsert; //or string if using GUID for Id //transaction and then dispose DB context using (var db = new MyContext()) { //add the entity object db.MyTable.Add(myObject); //now

How can I get Id of inserted entity in Entity framework when using defaultValue?

Is there a way to send a property with defaultValue but update it with the database computed result? There's a trigger in database, that for input -1 triggers a procedure which computes a new value. How to get the value back? <Property Name="ID" Type="int" Nullable="false" StoreGeneratedPattern="None" DefaultValue="-1" /> var x = new Stuff(); db.Stuff.AddObject(x); db.SaveChanges();

如何在使用defaultValue时在Entity框架中获取插入实体的Id?

有没有办法用defaultValue发送属性,但用数据库计算结果更新它? 数据库中有一个触发器,对于输入-1触发一个计算新值的过程。 如何获得价值回归? <Property Name="ID" Type="int" Nullable="false" StoreGeneratedPattern="None" DefaultValue="-1" /> var x = new Stuff(); db.Stuff.AddObject(x); db.SaveChanges(); return x.ID //gives -1, but the computed value should be different. 您需要在savechanges后

How to get id from entity for Auditlog in Entity Framework 6

I know it's several similar posts out there, but I cannot find any with a solution to this issue. I want to add a (sort of) AudioLog when adding, changing or deleting entities (soft-delete) in Entity Framework 6. I've overridden the SaveChanges and because I only want to add log entries for EntityStates Added, Modified or Deleted, I fetch the list before I call SaveChanges the first tim

如何从Entity Framework的Auditlog中获取实体的ID 6

我知道这里有几个类似的帖子,但我找不到解决此问题的任何解决方案。 我想在实体框架6中添加,更改或删除实体(软删除)时添加(排序)AudioLog。我已经重写了SaveChanges,并且因为我只想添加EntityStates添加,修改或删除的日志条目,在我第一次调用SaveChanges之前,我会获取该列表。 问题是,因为我需要记录已执行的操作,我需要检查实体的EntityState。 但是在调用SaveChanges后,所有条目的EntityState都不变。 public

ObjectContext with Entity Framework 6 inserting duplicates on existing related entities

I'm creating this to hopefully save a few people some wasted hours, or in my case a Saturday. The problem was as follows: My main entity was called case in this instance and upon passing validation, I would save to the object context, like so context.AddToCases(caseModel); context.SaveChanges(); The issue was that a case had a related incident. I was adding a context aware item called

ObjectContext与实体框架6在现有相关实体上插入重复项

我正在创造这个想要挽救一些浪费时间的人,或者在我的情况下是一个星期六。 问题如下: 我的主要实体在这个实例中被称为case,并且在通过验证后,我将保存到对象上下文中,如此 context.AddToCases(caseModel); context.SaveChanges(); 问题在于案件发生了相关事件。 我添加了一个名为事件的情境感知项目,我正在通过上下文来查找 caseModel.Incident = context.Incidents.SingleOrDefault(i => i.IncidentNumber == j

NullReferenceException vs. MSIL

I'm interpreting an exception report from a C# Windows Phone app. A method throws a NullReferenceException . The method goes: public void OnDelete(object o, EventArgs a) { if (MessageBox.Show(Res.IDS_AREYOUSURE, Res.IDS_APPTITLE, MessageBoxButton.OKCancel) == MessageBoxResult.OK) m_Field.RequestDelete(); } It's consistent with m_Field being null - there's simply nothin

NullReferenceException与MSIL

我正在解释来自C#Windows Phone应用程序的异常报告。 一个方法抛出一个NullReferenceException 。 该方法是: public void OnDelete(object o, EventArgs a) { if (MessageBox.Show(Res.IDS_AREYOUSURE, Res.IDS_APPTITLE, MessageBoxButton.OKCancel) == MessageBoxResult.OK) m_Field.RequestDelete(); } 这与m_Field为空是一致的 - 除此之外,没有其他可能是空的。 但这是神秘的部分。 来自StackTrace的S

Composite key entity and dont want to declare PK keys

OK so this should be simple. I have a class public class ProductConfig { public Category { get;set; } public Product { get;set; } } These two navigation properties are also primary keys for the table. Declaring PRoductId and CategoryIds are redundat. How can get configure the primary keys using the nav properties? edit: Stupid me. I forgot something very important in my question abo

复合关键实体并且不想声明PK密钥

好吧,这应该很简单。 我有一堂课 public class ProductConfig { public Category { get;set; } public Product { get;set; } } 这两个导航属性也是表的主键。 声明PRoductId和CategoryIds是冗余的。 如何使用nav属性来配置主键? 编辑:愚蠢的我。 我在上面的问题中忘记了一件非常重要的事。 以上两点是要指出配置。 然后,我们有第三个fk将选定的配置用于产品和类别的组合。 所以上述实体必须是物化实体 publ

inserting record with many to many relationship

My application was working fine when I had a one to many relationship between my entities but now I have tried to switch it to a many to many and I'm struggling on how to get it to correctly insert. I think I probably have something not quite right in my models. Now when I run a context.saveChanges() in my controller, it is failing because of this error: Failed in 97 ms with error: The INS

插入与多对多关系的记录

当我的实体之间有一对多关系时,我的应用程序工作正常,但现在我试图将其切换为多对多关系,而且我正在努力解决如何正确插入它的问题。 我想我的模型可能有些不太合适。 现在,当我在我的控制器中运行context.saveChanges()时,由于此错误而Failed in 97 ms with error: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.Products_dbo.Categories_CategoryID". The conflict occurred i

Updating a belongs to with Entity Framework

Very new to EF (coming from Rails Active Record), I have some entities like so (pseudo code): class Post int Id int CategoryId // Foreign Key Category Category string Title class Category int Id string Name In this scenario the categories are fixed, and should not be able to be edited through the Post, only assigned. I'm exposing an API, so lets say for example we recei

使用实体框架更新属于

EF(来自Rails Active Record)非常新,我有这样的实体(伪代码): class Post int Id int CategoryId // Foreign Key Category Category string Title class Category int Id string Name 在这种情况下,类别是固定的,不能通过邮政进行编辑,只能分配。 我正在公开一个API,所以让我们说,例如,我们收到一个特定的Post的HTTP PUT。 <Post> <Id>1</Id> <Category> &l

Using pdflatex to compile LaTeX file within C code

I am writing C code that writes a LaTeX file for me. I then attempt to compile the file using pdflatex in a non-interactive mode (as in I'm automating some process and don't want to wait for user input on fatal error). The LaTeX file is output at ./data/output_date.tex and I attempt to compile it using the command system("./pdflatex --interaction=nonstopmode --output-directory=data ./d

使用pdflatex在C代码中编译LaTeX文件

我正在编写为我写LaTeX文件的C代码。 然后,我尝试在非交互模式下使用pdflatex编译文件(如我自动执行某个过程,并且不希望等待用户输入致命错误)。 LaTeX文件在./data/output_date.tex输出,我尝试使用该命令编译它 system("./pdflatex --interaction=nonstopmode --output-directory=data ./data/output_date.tex"); 但是,我收到错误消息: This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian) entering