English 中文(简体)
如何忽略循环缓存数据, 才能将数据完全输入数据库存储?
原标题:How to ignore recursive cache data to fully get them on the database storage?

On my DBMS, I have two tables having one-to-many relationship (A <- B). At the first running, I retrieved some records of A (including B) like this:

var lst = from a in ctx.As.Include("Bs") select a;

So, everything is ok. But a few minutes later, I want to get them again because they could be changed on other apps.

我试着用

ctx.Refresh(RefreshMode.StoreWins, lst);

When I do that, the only things are refreshed is object from B, not A. Therefore, I must do another step like:

foreach (var a in lst) {
    ctx.Refresh(RefreshMode.StoreWins, a.Bs);
}

如果我没有将 Bs 包含在linq 语句中, 那么使用 Load 方法, 而不是 refresh

这里的问题是调用Refresh Load 太多倍,也许会降低性能。 我如何在不打电话这么多的情况下从数据库存储处重新装入它们?

谢谢!

最佳回答

但几分钟后...

背景是工作单位和工作单位通常不会花几分钟时间,所以您问题的基本答案是创造新的背景并再次执行查询。

如果您真的认为您的上下文必须持续如此长的时间(我怀疑它必须持续如此长的时间, 因为在这种情况下您不想覆盖本地更改), 您可以尝试 :

ctx.As.MergeOption = MergeOption.OverwriteChanges;
ctx.Bs.MergeOption = MergeOption.OverwriteChanges;
var lst = from a in ctx.As.Include("Bs") select a;
问题回答

暂无回答




相关问题
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. ...

热门标签