unit-of-work

IUnitOfWork how to use - best practice

≯℡__Kan透↙ 提交于 2019-12-07 10:31:55
问题 I'm using EF4.3.1 in a .Net4.0 web forms (not MVC!) application. I tend to use the repository pattern with an IUnitOfWork interface. But I'm wondering if I'm following best practices, especially since most examples I've followed are based on MVC apps. I will say it's only a small web app, so that may affect the solution choices. The solution currently has 3 projects, Model, Logic and Site. Model contains the codefirst entities and the IUnitOfWork interface. Logic contains the repositories and

Managing Transactions either in service layer or repository layer?

老子叫甜甜 提交于 2019-12-07 07:38:43
问题 I have a certain scenario where inserts and updates are done on multiple tables based on some constraints ..so its natural to use Transaction scope for these scenarios.Now,I have a respository layer and a service layer. service layer mediates the repository and the UI and is persistent ignorant. Now i m confused where to use the transactions either in service or in repository layers.I am not using any ORMs. I have also seen people advocating about Unit of work pattern for such scenarios. are

Unity framework - reusing instance

好久不见. 提交于 2019-12-07 04:38:10
问题 nobody loved my first question about this: Creating Entity Framework objects with Unity for Unit of Work/Repository pattern so I've managed to rephrase it to something you can read without falling asleep/losing the will to live. I'm creating an object, DataAccessLayer, that takes 2 interfaces in the constructor: IUnitOfWork, and IRealtimeRepository: public DataAccessLayer(IUnitOfWork unitOfWork, IRealtimeRepository realTimeRepository) { this.unitOfWork = unitOfWork; this.realTimeRepository =

Reusable Querying in Entity Framework WITHOUT Repository. How?

試著忘記壹切 提交于 2019-12-07 01:32:35
问题 Let me say, I have come to the conclusion (after a lot of trial) that Repository & Unit of Work when using Entity Framework is just wrong, wrong, wrong and this says why quite well. But I really hate on those embedded queries. Question is, where can I put them instead if I'm so against a repository, etc? (clean answers only please, examples much appreciated). I just nuked two projects containing my repositories, unit of work and interfaces with hundreds of files because the payback was

How to use joins with generic repository pattern - Entity Framework

女生的网名这么多〃 提交于 2019-12-06 19:10:29
I have a Generic Repository like below which handles my CRUD , for a single entity its easy to use, problem starts when i try to join my POCOs . Lets say I have these POCO, they are mapped using fluent api (many to many and One to many relation) : public class Student { public Student() { this.Courses = new HashSet<Course>(); } public int StudentId { get; set; } public string StudentName { get; set; } //FKs public virtual Standard Standard { get; set; } public int StdandardRefId { get; set; } public virtual ICollection<Course> Courses { get; set; } } public class Course { public Course() {

UnitOfWork in Action Filter seems to be caching

我的梦境 提交于 2019-12-06 18:53:31
问题 I have an MVC 3 site that uses IoC (Unity), and my model is generated w/ EF4 and POCOs. I am using an action filter to commit my UnitOfWork: public class UseUnitOfWorkAttribute : ActionFilterAttribute, IActionFilter { private readonly IUnitOfWork _unitOfWork; public UseUnitOfWorkAttribute() { _unitOfWork = IoCFactory.Instance.CurrentContainer.Resolve<IUnitOfWork>(); } void IActionFilter.OnActionExecuted(ActionExecutedContext filterContext) { _unitOfWork.Commit(); } void IActionFilter

Is unit of work a good pattern for transactions that will auto generate new objects (auto_increment id)?

寵の児 提交于 2019-12-06 12:53:24
From the unit of work pattern i uderstand a method of doing typic transactions based on some domain repostiries (using a repository per domain object) . Example : after defining some repository objects in the UoW object , commit those repositories based on theyr state . Also the repositories should not contain any transaction logic . What happens when an insert() leads to a creation of a new object (auto generated id) that later on is needed by another object in the same transaction ? Unit of work does not seem to work for this case . There could be even more specific and complex transaction

Design for multi-tenant app using SOA, UoW, Repository, DataContext & multiple databases

删除回忆录丶 提交于 2019-12-06 11:21:54
问题 Let me start by apologizing for the length of this post but I wanted to provide as much detail as possible to increase the chance of an answer. Thanks in advance. I’m adding new features to an existing application that integrates data from several databases. In short, it allows clients and/or their accountants to access and update financial information about their locations. The application has 3 tiers with a web client (I’m looking to replace this will a Silverlight client very soon), a

translate this into a generic repository pattern

放肆的年华 提交于 2019-12-06 09:21:58
I have started translating a project into a generic repository and unit of work pattern. So far I have been able to reverse engineer all direct context references in the controllers to a generic repository; however, I am having trouble with the following two lines of codes: `context.Entry(ticket).Collection(i => i.TicketItems).Load(); ticket.TicketItems.Clear();` This is what my controller was doing before to remove any reference between a Ticket and a TicketItem . There is a many-to-many relation between Ticket and TicketItem . So those two lines of code is what I was using before to remove

UOW + Repository + Autofac load two different DbContext

柔情痞子 提交于 2019-12-06 07:00:02
问题 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