开发者

linq2sql - where to enlist transaction (repository or bll)?

开发者 https://www.devze.com 2022-12-24 07:15 出处:网络
My app uses a business layer which calls a repository which uses linq to sql. I have an Item class that h开发者_C百科as an enum type property and an ItemDetail property.

My app uses a business layer which calls a repository which uses linq to sql.

I have an Item class that h开发者_C百科as an enum type property and an ItemDetail property.

I need to implement a delete method that:

(1) always delete the Item (2) if the item.type is XYZ and the ItemDetail is not null, delete the ItemDetail as well.

My question is where should this logic be housed?

If I have it in my business logic which I would prefer, this involves two separate repository calls, each of which uses a separate datacontext. I would have to wrap both calls is a System.Transaction which (in sql 2005) get promoted to a distributed transaction which is not ideal.

I can move it all to a single repository call and the transaction will be handled implicitly by the datacontext but feel that this is really business logic so does not belong in the repository.

Thoughts?

Carrie


I'm not sure I really understood your question, but if it's a single repository - could you have your repository expose two different methods handling the two types of deletion? Then the logic for determining which repository method to call would stay in the businesslayer where it seems to fit best?

Or maybe you can find some help in this post: Where should the transaction boundary be in a repository pattern?

0

精彩评论

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