简单数据工作单元实施
我试图在 Simple.Data 中找到工作单元模式的示例实现。有人有吗?我目前正在使用非通用存储库,并被告知实施 UoW 是要做的事情。
I'm trying to find an example implementation of the Unit Of Work pattern in Simple.Data. Does anybody have one? I'm currently using non generic repositories and have been told that implementing UoW is something to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想要从工作单元中得到的是事务涵盖的一组插入/更新/删除操作,那么这是受支持的:(
注意:此代码假设您使用的是 Ado 适配器,IDENTITY 指的是 SQL Server,但代码可以在任何 Ado 提供程序和任何支持事务的适配器上运行。)
如果您希望能够创建一批操作并一次性运行它们,那么目前不直接支持,但是我愿意接受功能请求或补丁。
如果您要跟踪对象的更改,可能需要了解的一件事是,从 Simple.Data 0.9 开始,SimpleRecord 实现了 ICloneable,因此您可以在选择记录后立即获取记录的副本,并在保存时使用它进行比较后退。我将很快推出一个版本,支持 Update(current, Original) 方法,该方法将执行乐观并发更新。
If what you want from the Unit of Work is a set of insert/update/delete operations covered by a transaction, then that is supported:
(Note: this code assumes you're using the Ado adapter, and IDENTITY refers to SQL Server, but the code will work on any of the Ado providers and on any adapter which supports transactions.)
If you want to be able to create a batch of operations and run them all in one go, then that's not directly supported at the moment, but I'm open to feature requests or patches.
If you're after change tracking on objects, one thing that might help to know is that as of Simple.Data 0.9, SimpleRecord implements ICloneable, so you can take a copy of a record just after selecting it and use it for comparison when saving back. I'm going to push a release soon with support for an Update(current, original) method which will do optimistic-concurrency updates.