unit-of-work

Unit of Work Design Pattern [closed]

被刻印的时光 ゝ 提交于 2019-12-04 12:33:21
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 19 days ago . Does anyone have any good links about a practical example of Unit of Work pattern with LINQ to SQL 回答1: The only resource that I know off is the code for Suteki Shop, an ASP.Net MVC application which uses LINQ To SQL. One change they carried out recently was to implement the Unit of work pattern in all the

UOW + Repository + Autofac load two different DbContext

我的未来我决定 提交于 2019-12-04 11:46:35
I'm facing an issue today and I'm unable to solve it, I searched a lot and can't get into a solution, please help me if you can. I'm implementing a MVC application which uses EF + Repository Pattern + Unit Of Work with Autofac as the Dependency Injector. I was able to work with one DbContext class, but I'm facing a situation where I need to use another DbContext instance (which access another database with another user credentials) Let me explain better: I have EntityA which comes from database A (and have a DatabaseA_Context class). So I need a EntityB, which comes from database B (with its

Unit of work pattern

白昼怎懂夜的黑 提交于 2019-12-04 10:48:48
I'm looking for some advices about the unit of work pattern. Is the commit on the unit of work called multiple times or just one time and then leaving the object for garbage collection? Is it a good idea to inject the unit of work play or should I pass it around in method call when asking objects to perform some work? Instances of types that implement the unit of work pattern usually have a single owner that needs to control its lifetime. Methods like Commit , Open , Close , and Dispose are often strong signals that a type should be controlled explicitly (or placed behind an abstraction if

Using the Generic repository/Unit of work pattern in large projects

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 08:45:11
问题 I'm working on a quite large application. The domain has about 20-30 types, implemented as ORM classes (for example EF Code First or XPO, doesn't matter for the question). I've read several articles and suggestions about a generic implementation of the repository pattern and combining it with the unit of work pattern, resulting a code something like this: public interface IRepository<T> { IQueryable<T> AsQueryable(); IEnumerable<T> GetAll(Expression<Func<T, bool>> filter); T GetByID(int id);

Tracking model changes in SQLAlchemy

狂风中的少年 提交于 2019-12-04 08:19:27
问题 I want to log every action what will be done with some SQLAlchemy-Models. So, I have a after_insert, after_delete and before_update hooks, where I will save previous and current representation of model, def keep_logs(cls): @event.listens_for(cls, 'after_delete') def after_delete_trigger(mapper, connection, target): pass @event.listens_for(cls, 'after_insert') def after_insert_trigger(mapper, connection, target): pass @event.listens_for(cls, 'before_update') def before_update_trigger(mapper,

can you have multiple transactions occur inside one session in nhibernate? And is it a bad idea?

点点圈 提交于 2019-12-04 06:51:09
I'm thinking about making my own IUnitOfWork implementation for an NHibernate persistence layer. It seems that the right way to do this would be to have the ISession and the ITransaction instantiated in the constructor, and then disposed in the destructor or the Dispose() method. Of course, if someone invokes the Save() method, then the ISession would be flushed and the ITransaction would be complete, so after calling Save() , there would not be a valid open transaction to Save() again... unless I committed the first transaction and immediately opened another, new transaction. But is this a

Repository + UnitOfWork pattern for entity framework

﹥>﹥吖頭↗ 提交于 2019-12-04 03:19:57
I was searching the net up and down and I didn't manage to find a suitable design for my application. I am looking for Repository+UnitOfWork pattern that will manage connections and dispose them automatically when done. I need to support both web application where each request will have its own UnitOfWork and windows application where each thread will have its own UnitOfWork. I need the patters to dispose automatically the UnitOfWork whrn request/thread is done. I also would like to support rolback in case of exception. Right now I use StructureMap so I don't care to continue use it in the

Multiple database contexts when using repository pattern

ε祈祈猫儿з 提交于 2019-12-03 22:13:01
I am a bit lost right now... I've never seen this much divergent information regarding solution to the problem. But let us start from the beginning. I am using ASP.NET MVC with Repositories injected to Controllers, thanks to the Ninject. I have 2 simple Entities: Admin with a list of created blog entries and Entries with one virtual Admin field. Admin: public class Admin { [Key, ScaffoldColumn(false)] public int Id { get; set; } [Required(ErrorMessage = "Zły login.")] [StringLength(20), MinLength(3)] [RegularExpression(@"^[a-zA-Z0-9]*$", ErrorMessage = "Special characters are not allowed.")]

Single threading a task without queuing further requests

我是研究僧i 提交于 2019-12-03 17:43:45
问题 I have a requirement for a task to be executed asynchronously while discarding any further requests until the task is finished. Synchronizing the method just queues up the tasks and doesn't skip. I initially thought to use a SingleThreadExecutor but that queues up tasks as well. I then looked at the ThreadPoolExecutor but it reads the queue to get the task to be executed and therefore will have one task executing and a minimum of one task queued (the others can be discarded using

Preparing for multiple EF contexts on a unit of work - TransactionScope

Deadly 提交于 2019-12-03 17:06:31
I'm thinking of the options in regards to implementing a single unit of work for dealing with multiple datasources - Entity framework. I came up with a tentative approach - for now dealing with a single context - but it apparently isn't a good idea. If we were to analyze the code below, would you consider it a bad implementation? Is the lifetime of the transaction scope a potential problem? Of course if we wrap the transaction scope with different contexts we'd be covered if the second context.SaveChanges() failed... using System; using System.Collections.Generic; using System.Linq; using