开发者

What is a common practice when trying to do Inserts and Deletes with Entity Framework and Unit Of Work, all in the same commit?

I've implimented a Unit of Work pattern with开发者_如何学JAVA my Entity Framework repository. ** golf clap **

Now i'm wondering what the common practice is, for doing multiple insets and/or deletes all within the same commit?

for example: Imagine I wish add 5 new objects/entities and for some reason, now delete entity #3.

// Arrange.
var uow = new UnitOfWork() { ... };
var myRepository = new MyRepository(uow);
var entity1 = new Entity(){ ... };
// ... snip snip ..

// Acts.
myRepository.Add(entity1);
myRepository.Add(entity2);
myRepository.Add(entity3);
myRepository.Add(entity4);
myRepository.Add(entity5);

 // do some logic ...

myRepository.Delete(entity3);

uow.Commit();

Will this work .. as in .. should the entities be added and THEN 1 removed from the db? Or will this only happen against the EF Entities list?

Is this bad practice? ie. never mix adds/updates with deletes? always commit before a delete?


It's allowed, but the order isn't guaranteed. EF will try to figure out the best order, and throw if it can't. If this sounds hard to test comprehensively, well, you're probably right.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜