unit-of-work

Singleton Per Call Context (Web Request) in Unity

a 夏天 提交于 2019-12-17 08:11:07
问题 A few days ago, I had an issue with ASP.Net threading. I wanted to have a singleton object per web request. I actually need this for my unit of work. I wanted to instantiate a unit of work per web request so that identity map is valid through out the request. This way I could use an IoC to inject my own IUnitOfWork to my repository classes transparently, and I could use the same instance to query and then update my entities. Since I am using Unity, I mistakenly used PerThreadLifeTimeManager.

Creating Entity Framework objects with Unity for Unit of Work/Repository pattern

ⅰ亾dé卋堺 提交于 2019-12-14 03:43:23
问题 I'm trying to implement the Unit of Work/Repository pattern, as described here: http://blogs.msdn.com/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx This requires each Repository to accept an IUnitOfWork implementation, eg an EF datacontext extended with a partial class to add an IUnitOfWork interface. I'm actually using .net 3.5, not 4.0. My basic Data Access constructor looks like this: public DataAccessLayer(IUnitOfWork unitOfWork,

Read uncomitted data from HasMany-relationship with NHibernate

半腔热情 提交于 2019-12-13 07:08:22
问题 I have an NHibernate map which defines a HasMany-relationship on a type, i.e. a class has a list of another class. I would like NHibernate to be able to read uncommitted data including the list resulting from the HasMany-relationship. I have isolationlevel ReadUncomitted and I am able to write data and read it back before committing. However, the list is always empty, unless I commit first. Is there a way to make NHibernate populate objects with data from HasMany-relationships? EDIT It turns

ASP.Net MVC 3 - unitOfWork.Commit() not saving anything

早过忘川 提交于 2019-12-13 02:47:27
问题 I created a web application using ASP.Net MVC 3 and EF 4.1, and I am using the UnitOfWork pattern, but nothing is getting committed to the database. All this is quite new to me, and I don't know where to start to resolve this issue. I based myself on this post to create my web application: http://weblogs.asp.net/shijuvarghese/archive/2011/01/06/developing-web-apps-using-asp-net-mvc-3-razor-and-ef-code-first-part-1.aspx The final code, which can be obtained here also has a service layer and

UnitOfWork with NInject design issues

社会主义新天地 提交于 2019-12-12 17:17:17
问题 I have my UnitOfWork class in DataAccess project and to resolve my IUnitOfWork interface (with UnitOfWork class), I need to use Ninject to Bind the IUnitOfWork interface with UnitOfWork class in my web project. To do this I need to refer my DataAccess project (which contains UnitOfWork class) in the Web project. Is this good design wise? I mean referring DataAccess in the web project seems to be a bad idea & I never did that. So, please advise me on what to do? 回答1: If you are not comfortable

How can I inject the Repositories to the UnitOfWork?

橙三吉。 提交于 2019-12-12 14:22:44
问题 I've implemented my UnitOfWork so that it keeps references to all repositories. public interface IUnitOfWork { void Commit(); void RollBack(); } public interface IMyUnitOfWork : IUnitOfWork { IFooRepository Foos { get; } IBarRepository Bars { get; } // Other repositories ... } Note that the repositories implements a generic type of repository interface. public interface IFooRepository : IRepository<Entities.Foo> { // FooRepository specific methods goes here. } public interface IRepository<T>

applying unit of work in a generic repository

删除回忆录丶 提交于 2019-12-12 04:05:34
问题 I'm learning on doing repository with unit of work. I also know how to do DI/IOC. But my problem is I can't figure out where to apply Unit of Work in my code. Below is a Generic Repository. public abstract class Repository<T, C> : //IDisposable, IRepository<T> where T : class where C : DbContext, new() { private C entities = new C(); public C Context { get { return this.entities; } set { this.entities = value; } } public virtual void Insert(T entity) { this.entities.Set<T>().Add(entity); } //

Repository and UoW pattern with service layer

半世苍凉 提交于 2019-12-12 03:40:00
问题 I'm using Repository and UoW pattern. My services look like this: public class MyService : IService { private readonly IUnitOfWork<MyContext> unitOfWork; private readonly IMyRepository myRepository; public MyService(IUnitOfWork<MyContext> unitOfWork, IMyRepository myRepository) { this.unitOfWork = unitOfWork; this.myRepository = myRepository; } //Methods... } Within services, I need to use other entities (for example to check for rights, etc). Is it recommended to use the relevant

Multiple string connections in EF DbContext

 ̄綄美尐妖づ 提交于 2019-12-12 01:33:13
问题 I’m developing a MVC Website based in codeplex EFMVC solution, and I’m using Entity Framework and Repository, Unit of Work and Command Patterns. My website needs to be a SaaS solution (software as a service) multiple database. In my legacy Asp.Net WebForms I have a XML file that holds all the different string connections and I’m trying to use the same strategy. So in my LoginController I create a command that has company (to identify in which database will be connected) username and password.

Why I am not able to get recently added objects (yet to be saved in database) from repository

五迷三道 提交于 2019-12-11 20:00:42
问题 I am developing an asp.net mvc4 application in which repository and unit of work pattern was implemented. I want some solution to get the newly added data from repository means i want to able to manipulate the data's before it saving into database. I learned like the objects are available in the EF Change Tracking mechanism, so they should be available , even though it has not yet been saved to the database. By keeping this in mind only am doing the below stuffs Below is my controller...