unit-of-work

entity framework + repository + unit or work question

青春壹個敷衍的年華 提交于 2019-11-29 05:15:23
问题 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

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

孤街浪徒 提交于 2019-11-29 03:51:44
问题 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

Multiple DbContexts in N-Tier Application

你。 提交于 2019-11-29 00:06:37
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 my UnitOfWork that is created in my Service ctor but every way I look at it I'm still tied to the

Symfony2 / Doctrine2 throwing index error when flushing the entity manager

廉价感情. 提交于 2019-11-28 23:41:07
Three entities are involved here: Deployment , DeploymentStep , and DeploymentStatusLog . I'll start by pasting the relevant definitions of those classes src/My/Bundle/Entity/Deployment.php <?php namespace My\Bundle\Entity; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\PersistentCollection; /** * @ORM\Table(name="deployment") * @ORM\Entity() */ class Deployment { /** * Status Log Entries for this deployment * * @var \Doctrine\ORM\PersistentCollection * * @ORM\OneToMany(targetEntity="DeploymentStatusLog", mappedBy="deployment", cascade={

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

孤者浪人 提交于 2019-11-28 21:27:31
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 transaction on action executing, and on action executed I end the transaction and close the session. This was

Register Generic Type with Autofac

给你一囗甜甜゛ 提交于 2019-11-28 20:18:04
I have UnitofWork class and it implement IUnitOfWork. I try to register that with autofac : var builder = new ContainerBuilder(); builder .RegisterGeneric(typeof(UnitOfWork<Repository<>,>)) .As(typeof(IUnitOfWork)) .InstancePerDependency(); Implementation is: public class UnitOfWork<T, O> : IUnitOfWork where T : Repository<O> where O : BaseEntity { } public interface IUnitOfWork : IDisposable { void SaveChanges(); } Gives an error "Type expected" but this one work on another project: public class Repository<T> : GenericRepository<T> where T : BaseEntity { public Repository(IDbContext context)

Benefit of using Unit of Work and Repository Patterns with Entity Framework

雨燕双飞 提交于 2019-11-28 19:44:41
问题 According to MSDN, DbContext is defined as: Represents a combination of the Unit-Of-Work and Repository patterns and enables you to query a database and group together changes that will then be written back to the store as a unit. Since DbContext implements the Unit of Work and Repository patterns, then why does this ASP.NET tutorial and other resources that I have found on the Internet demonstrate the use of DbContext with custom implementations of the Unit of Work and Repository patterns?

Entity Framework + Repository + Unit of Work

倖福魔咒の 提交于 2019-11-28 19:12:58
问题 I'm thinking about starting a new project using EF 4 and going through some articles, I found some articles about EF with repository pattern and unit of work ( http://tdryan.blogspot.com/2011/03/another-entity-framework-4-repository_15.html and http://blogs.msdn.com/b/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx) I'm using the first one (part1, part2 and part3). They are very similar. I'm a newbie in this scenario. I'm confusing between

Onion Architecture, Unit of Work and a generic Repository pattern

六月ゝ 毕业季﹏ 提交于 2019-11-28 17:17:43
This is the first time I am implementing a more domain-driven design approach. I have decided to try the Onion Architecture as it focuses on the domain rather than on infrastructure/platforms/etc. In order to abstract away from Entity Framework, I have created a generic repository with a Unit of Work implementation. The IRepository<T> and IUnitOfWork interfaces: public interface IRepository<T> { void Add(T item); void Remove(T item); IQueryable<T> Query(); } public interface IUnitOfWork : IDisposable { void SaveChanges(); } Entity Framework implementations of IRepository<T> and IUnitOfWork :

Entity Framework using Repository Pattern, Unit of Work and Unity

安稳与你 提交于 2019-11-28 16:22:23
问题 Using a combination provided from this example and this implementation I am trying to create a solution that decouples the UnitOfWork class from the individual repositories, as they violate the Open-Closed Principle, since every time you added a new repository you would have to modify the UnitOfWork class. I am using Unity as the IoC container to wire up dependencies. The problem I have is that in automatically wiring up the UnitOfWork , IDbContext and the repositories ( IEmployeeRepository