unit-of-work

Multiple generic repositories in unitofwork?

人盡茶涼 提交于 2019-12-01 00:47:59
Lets say I have 2 tables. ProductCategory and Product . I have 1 generic repository that can handle both tables: public class GenericRepository<T> : IRepository<T> But when using unit of work pattern, am I forced to create a repository for ALL tables in my database? public interface IUnitOfWork : IDisposable { int SaveChanges(); IRepository<ProductCategory> ProductCategoryRepository { get; } IRepository<Product> ProductRepository { get; } } Is there not a way I can add the generic repository to the unit of work class? You can add a generic method to the IUnitOfWork interface: public interface

What is the correct way to use Unit of Work/Repositories within the business layer?

左心房为你撑大大i 提交于 2019-11-30 20:30:59
Having built a small application using the Unit of Work/Repository pattern, I am struggling to understand how to use this properly within my business layer. My application has a a data access layer which can be either NHibernate or the Entity Framework. I can switch between these easily. I have a number of repositories, for example, Customer, Order etc. My unit of work will be either an ISession or an Object Context depending on which DAL I want to test with. My business layer contains a single business method - CreateOrder(). What I am struggling to understand is where in the business layer I

Need a simple example of using nhibernate + unit of work + repository pattern + service layer + ninject

本小妞迷上赌 提交于 2019-11-30 10:40:01
问题 I am using nhibernate + fluent nhibernate asp.net mvc 3 ninject Currently I am using nhibernate, ninject with the repository pattern and service layers. So I have this ninject public class NhibernateSessionFactory { public ISessionFactory GetSessionFactory() { ISessionFactory fluentConfiguration = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("ConnectionString"))) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Framework.Data

Unit of Work + Repository Pattern: The Fall of the Business Transaction Concept

点点圈 提交于 2019-11-30 10:10:14
问题 Combining Unit of Work and Repository Pattern is something used fairly widely nowadays. As Martin Fowler says a purpose of using UoW is to form a Business Transaction while being ignorant of how repositories actually work (being persistent ignorant). I've reviewed many implementations; and ignoring specific details (concrete/abstract class, interface,...) they are more or less similar to what follows: public class RepositoryBase<T> { private UoW _uow; public RepositoryBase(UoW uow) //

How to update complex model in ASP.NET MVC 3

假如想象 提交于 2019-11-30 09:50:32
I am trying to update a complex model in a single view. I am using ASP.NET MVC3, Entity Framework with Code first, unit of work, generic repository pattern.. but when I try to update the model, i come up with this error: A referential integrity constraint violation occurred: The property values that define the referential constraints are not consistent between principal and dependent objects in the relationship. Here is my simplified view model: public class TransactionViewModel { public Transaction Transaction { get; set; } public bool IsUserSubmitting { get; set; } public IEnumerable

Multiple DbContexts in N-Tier Application

自古美人都是妖i 提交于 2019-11-30 07:01:04
问题 I'm creating my first N-Tier MVC application and I've run into a road block with how to manage multiple DbContexts with my database first approach. I have the following layers Presentation Service (WCF) Business Data Access I don't want an entity framework reference in my service layer but I don't see how to create an Interface or something to manage two contexts. I have it working with a single context warpped in a IDatabaseFactory but I can't seem to find an approach to manage two. Below is

Entity Framework Core 1.0 unit of work with Asp.Net Core middleware or Mvc filter

て烟熏妆下的殇ゞ 提交于 2019-11-30 06:46:42
问题 I am using EF Core 1.0 (previously known ad EF7) and ASP.NET Core 1.0 (previously known as ASP.NET 5) for a RESTful API. I'd like to have some unit of work scoped to an http request in such a way that when responding to the HTTP request either ALL the changes made to the DbContext will be saved onto the database, or none will be saved (if there was some exception, for example). In the past I have used WebAPI2 for this purpose with NHibernate by using an Action filter where I begin the

ASP.NET MVC, Ninject, single instance per request for multiple constructors

不想你离开。 提交于 2019-11-30 06:26:09
Im trying to implement an unit of work pattern by passing an unit of work instance into my repositories. Relevant code from Global.asax. public class SiteModule : NinjectModule { public override void Load() { Bind<IUnitOfWork>().To<SqlUnitOfWork>() .InRequestScope() .WithConstructorArgument("connectionString", ConfigurationManager.ConnectionStrings["Entities"].ConnectionString); Bind<IProductRepository>().To<ProductRepository>(); Bind<ICategoryRepository>().To<CategoryRepository>(); } } Repository constructors: public class ProductRepository { IUnitOfWork unitOfWork; public ProductRepository

entity framework + repository + unit or work question

耗尽温柔 提交于 2019-11-30 05:27:52
I'm thinking about starting a new project using EF 4 and going through some articles, I found an article about EF with repository pattern and unit of work ( http://blogs.msdn.com/b/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx ) Looking at that article, it uses the ObjectContext as the UnitOfWork and it passes it to the Repository. My question is what if I have 2 ObjectContext which mean I will have 2 unit of work, but I actually wants all the operation perform on those 2 context to be one single unit of work, is this scenario possible? I

Entity Framework 4 - Where to put “ApplyCurrentValues” Logic?

我的梦境 提交于 2019-11-30 05:23:30
I'm using the " stub technique " to update my POCO's (used in a detached context, ASP.NET MVC). This is the code i currently have in my controller (which works): [HttpPost] public ActionResult Edit(Review review) { Review originalReview = _userContentService.FindById(review.PostId) as Review; var ctx = _unitOfWork as MySqlServerObjectContext; ctx.ApplyCurrentValues("MyEntities.Posts", review); _unitOfWork.Commit(); // ..snip - MVC stuff.. } As you can see, there is code smell everywhere. :) A few points: I use Dependency Injection (interface-based) for basically everything I use the Unit of