English 中文(简体)
实体框架——访问删除数据库的次数 目的
原标题:Entity Framework - How many trips to the database on DeleteObject

该实体框架是否实际两次访问数据库?

    var result = from p in entities.people where p.id == 6 select p;
    entities.DeleteObject(result);

它袭击我,可能要删除目标,就会迫使第一次旅行取得结果,而反对与之合作的国家将履行删除职能。

如果是这样,我如何避免第二次旅行? 在单一数据库旅行的实体框架中,如何逐个顺序去除?

感谢!

http://www.ohchr.org。

我的原始例子令人误解,因为它是主要钥匙的问答。 我怀疑真正的问题是,是否有一种能够从可贵的物品中删除的单程功能。 例如:

    var result = from p in entities.people where p.cityid == 6 select p;

    foreach (var r in result)
    {
        entities.DeleteObject(r);
    }

(注意到询问是外国钥匙,因此可能会有多重结果)。

问题回答

你可以这样做:

  entities.ExecuteStoreCommand("DELETE FROM people WHERE people.cityid={0}", 6);

这是对数据库的一次访问,可以肯定并有效。

EDIT: Also, take a look here, they suggest the same solution. And to answer the question, this is the only way to delete entities, not referenced by primary key, from a database using entity framework, without fetching these entities (and without writing some helper extension methods like suggested in this answer).





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

热门标签