English 中文(简体)
实体框架 4 - 内容如何。 是否应当工作?
原标题:Entity Framework 4 - How is ObjectContext.Refresh() supposed to work?

当我用RefreshMode打电话时。 属于我情况的实体的库存和数据库的数值与实体目前持有的数值不同,即使我的物体实体没有变化,我的实体是否应该更新数据库的现值?

当编辑一个实体时,我们便会发现一个新情况,并即时发行一个新目录,把我们这一类别的现有实体从数据库中装上。 改变我们的地图册,正确地把“拯救”的数值节省到数据库。 在回到所谓的“观点”之后,我们就使用RefreshMode的原有情况再次发言。 尽管通过SSMS正确更新了数据库中的数值,但这并没有更新各实体在这方面的价值。 我应该研究什么想法来解决这一问题?

EDIT: Simple example of how we are doing things:

var context1 = new Model1();
LoadContext(); //loads all the data from the database and adds them to the context
var context2 = new Model1();
var SelectedObject = context1.Table1.First();
OurObject selectedObjectForEdit = new OurObject(SelectedObject.ObjectId);
context2.Table1.Add(selectedObjectForEdit);
selectedObjectForEdit.Name = "new name";
context2.SaveChanges();
context1.Refresh(RefreshMode.StoreWins, SelectedObject);
问题回答

您必须注意重温一个在上不在其他情况下就座的实体。 仅举一个有其他情况的实体,可人工操作,无任何例外,即使有SoreWins也没有任何变化。

var context1 = new Model1();
var context2 = new Model1();
context1.Table1.First().Caption = "a";
var entity = context2.Table1.First();
context1.SaveChanges();
//below code run without exception but any change not affected
context1.Refresh(RefreshMode.StoreWins, entity);

情况1 迫使一个包含背景2的实体复职。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...