unit-of-work

Entity Framework 6 and Unit Of Work… Where, When? Is it like transactions in ado.net?

牧云@^-^@ 提交于 2019-11-27 11:07:50
Creating a new MVC project and like the idea of repositories in the data layer, so i have implemented them. I have also created a Service layer to handle all business logic and validation, this layer in turn uses the appropriate repository. Something like this (I am using Simple Injector to inject) DAL LAYER public class MyRepository { private DbContext _context; public MyRepository(DbContext context) { _context = context; } public MyEntity Get(int id) { return _context.Set<MyEntity>().Find(id); } public TEntity Add(MyEntity t) { _context.Set<MyEntity>().Add(t); _context.SaveChanges(); return

Onion Architecture, Unit of Work and a generic Repository pattern

被刻印的时光 ゝ 提交于 2019-11-27 10:22:55
问题 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 :

ASP.NET Identity with Repository and Unit of Work

心不动则不痛 提交于 2019-11-27 09:38:12
问题 I'm learning Repository and Unit of Work patterns in ASP.NET MVC 5 application with Entity Framework 6. I had already read a lot of tutorials and articles, but almost all of them are condradictory. Ones say that Repository and Unit of Work patterns are good, others say DbContext is already a repository and unit of work, others say something similar, but offer a completely different approach. I tried all these different approaches (well, maybe not all of them) and still struggling regarding

Where does Unit Of Work belong w/ EF4, IoC (Unity), and Repository?

梦想与她 提交于 2019-11-27 06:54:34
问题 I see several questions relating somewhat to this, but I still can't find the answer I'm looking for, so I'm posting my question. If another question holds the answer (and I'm just not seeing it), please point me to it. I'm trying to figure out where my UnitOfWork belongs -- and specifically, gets created -- when using EF4 and Unity with the Repository pattern. Basically, I have a service that is used to implement my business logic. This service constructor takes in the repository, so the

Entity Framework 6 Code First - Is Repository Implementation a Good One?

萝らか妹 提交于 2019-11-27 05:47:26
I am about to implement an Entity Framework 6 design with a repository and unit of work. There are so many articles around and I'm not sure what the best advice is: For example I realy like the pattern implemented here: for the reasons suggested in the article here However, Tom Dykstra (Senior Programming Writer on Microsoft's Web Platform & Tools Content Team) suggests it should be done in another article: here I subscribe to Pluralsight , and it is implemented in a slightly different way pretty much every time it is used in a course so choosing a design is difficult. Some people seem to

Correct use of the NHibernate Unit Of Work pattern and Ninject

江枫思渺然 提交于 2019-11-27 00:24:50
问题 I have the following implementation and would like some feedback as to whether it makes correct use of NHibernate for sessions and transactions. public interface IUnitOfWork : IDisposable { ISession CurrentSession { get; } void Commit(); void Rollback(); } public class UnitOfWork : IUnitOfWork { private readonly ISessionFactory _sessionFactory; private readonly ITransaction _transaction; public UnitOfWork(ISessionFactory sessionFactory) { _sessionFactory = sessionFactory; CurrentSession =

SQL Server : is there any performance penalty for wrapping a SELECT query in a transaction?

自闭症网瘾萝莉.ら 提交于 2019-11-26 23:41:23
问题 As learning exercise and before trying to use any ORM (like EF) I want to build a personal project using ADO.NET and stored procedures. Because I don't want my code to become a mess over time, I want to use some patterns like the repository and UoW patterns. I've got almost everything figured it out, except for the transaction handling. To somehow 'simulate' a UoW, I used this class provided by @jgauffin, but what's stopping me from using that class is that every time you create a new

Looking for a Ninject scope that behaves like InRequestScope

孤人 提交于 2019-11-26 23:16:07
On my service layer I have injected an UnitOfWork and 2 repositories in the constructor. The Unit of Work and repository have an instance of a DbContext I want to share between the two of them. How can I do that with Ninject ? Which scope should be considered ? I am not in a web application so I can't use InRequestScope . I try to do something similar... and I am using DI however, I need my UoW to be Dispose d and created like this. using (IUnitOfWork uow = new UnitOfWorkFactory.Create()) { _testARepository.Insert(a); _testBRepository.Insert(b); uow.SaveChanges(); } EDIT: I just want to be

How to implement Unit of Work that works with EF and NHibernate

早过忘川 提交于 2019-11-26 22:21:58
问题 I was working on a Unit of Work implementation that works both in Entity Framework 4.1 and NHibernate. Find below the skeleton of my implementation details IUnitOfWork definition public interface IUnitOfWork { IRepository<LogInfo> LogInfos { get; } IRepository<AppInfo> AppInfos { get; } void Commit(); void Rollback(); } IRepository definition public interface IRepository<T> where T : class, IEntity { IQueryable<T> FindAll(); IQueryable<T> FindWhere(Expression<Func<T, bool>> predicate); T

Is UnitOfWork and GenericRepository Pattern redundant In EF 4.1 code first?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 20:04:25
Wondering if I need to use the Genericrepository pattern and UnitOfWork to mock the repository.I am using MOQ.Is it now redundant since I have noticed that EF 4.1 has IDBSet. I have not figured out how to write something generic that usic IDBSet .If you have an example where you implement IDBSet can you show it to me? Any suggestions? Ladislav Mrnka This is duplicate of many topics already discussed on SO but I agree that some of them can be hard to find because they are nested in other question What's the point of Generic repository in EF 4.1 Challenges with testable and mockable code in EF