repository-pattern

How do I use DTO's with EF, Autofac, and a generic data repository?

回眸只為那壹抹淺笑 提交于 2019-12-23 05:22:09
问题 How do I use DTO's with EF, Autofac, and a generic data repository? I'm in the process of setting up a new project and have configured my DI/IoC (Autofac), using a generic repository for data access through EF, and created an OData service endpoint, ContentTypesController . Here's the top part of the controller: public class ContentTypesController : ODataController, IContentTypesController { // add repository reference private readonly IRepository<ContentType> _repository; private

Does a new() EF Context in the constructor of a controller properly handle the disposal?

亡梦爱人 提交于 2019-12-23 05:13:42
问题 ASP.NET website recommends implementing Disposable on my repository which affects my datacontext. Is it sufficient for me to initialize the datacontext here, and casually let ASP.NET dispose of the resources? Under what conditions will it not get called? I am debugging frequently (ending the debug session mid page) and noticed that I needed to reboot to reclaim some memory. 回答1: MVC will not dispose any IDisposable instances you create. You are in-charge of disposing them. You can either over

How to add multi DbContext With UnitOfWork & DatabaseFactory & Generic Repository

可紊 提交于 2019-12-23 04:57:10
问题 I want to add TWO DbContext in My ASP.NET MVC 5 App, One DbContext For ASPIdentity and The Other For My APP DB. I am Using Repository Pattern. m y problem is, How to To specify the Entity of each DbContext in BaseRepository ? Here Is What I did. 1- DatabaseFactory & IDatabaseFactory public class DatabaseFactory<T> where T : DbContext,new() { private T dbContext; public T Init() { return dbContext ?? (dbContext = new T()); } } public interface IDatabaseFactory<T> where T : DbContext { T Init()

Entity Framework 4 CTP 5 POCO - How to Unit Test my Repository<T>

◇◆丶佛笑我妖孽 提交于 2019-12-23 04:48:08
问题 This is the 2nd part of another question Entity Framework 4 CTP 4 / CTP 5 Generic Repository Pattern and Unit Testable), where I asked how to implement a generic repository pattern using EF 4 POCO. Now that my repository is working, I would like to know how to unit test my Repository (TDD or BDD). Thanks all. 回答1: Hey I wrote some blog posts on doing this with SpecFlow. But that was a disaster when it got complex. I tried to implement a testing repository which was also a disaster. Trying to

Entity Framework 4 CTP 5 POCO - How to Unit Test my Repository<T>

纵然是瞬间 提交于 2019-12-23 04:48:00
问题 This is the 2nd part of another question Entity Framework 4 CTP 4 / CTP 5 Generic Repository Pattern and Unit Testable), where I asked how to implement a generic repository pattern using EF 4 POCO. Now that my repository is working, I would like to know how to unit test my Repository (TDD or BDD). Thanks all. 回答1: Hey I wrote some blog posts on doing this with SpecFlow. But that was a disaster when it got complex. I tried to implement a testing repository which was also a disaster. Trying to

How to force EF LINQ query generation without execution

不想你离开。 提交于 2019-12-23 04:04:43
问题 I have a nicely decoupled app and dependency-injected app that uses Entity Framework 4.1 CodeFirst to expose IQueryable through a repository pattern. It's easy enough to mock the underlying datastore when testing the repository clients, however a certain class of bug is not being caught: The repository clients are free to layer their own LINQ predicates, joins, etc on top of what the repository returns: { _myRepository.FindAll().Where( x => x.Id == 3 && SomeMethod(x.Name) == "Hello" ); } This

Generic repository implementation with EF

喜欢而已 提交于 2019-12-23 02:41:23
问题 For a simple repository public interface ISimpleRepository<T> { IApplicationState AppState { get; set; } void Add(T instance); void Delete(T instance); void Delete(Guid rowGuid); IQueryable<T> GetAll(); T Load(Guid rowGuid); void SaveChanges(); void Update(T instance); } my implementation of the Load() method for specific repository for class Product might look like this: public Product Load(Guid rowid) { return (from c in _ctx.Products where c.id == rowid select c).FirstOrDefault(); } Now

Implementing a Repository<T> that returns a domain model mapped from an EF Entity

做~自己de王妃 提交于 2019-12-22 22:19:57
问题 I have the following application structure, based on the onion architecture by Jeffery Palermo (ref link). So my Core is not dependant on anything, my Infrastructure is dependent on my Core My Core has the Repository Contract and my Infrastructure implements it. The Implementation gets Injected by my IoC Container Core -Interfaces --IRepository<TDomainModel> -Domain --Person Infrastructure -Data --Repository<TDomainModel> (Implementation) -Entities --Ef.edmx So this wouldn't be a problem if I

translate this into a generic repository pattern

不羁岁月 提交于 2019-12-22 18:27:14
问题 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

Handling Multiple Mocks and Asserts in Unit Tests

烂漫一生 提交于 2019-12-22 12:43:26
问题 I currently have a repository that is using Entity Framework for my CRUD operations. This is injected into my service that needs to use this repo. Using AutoMapper, I project the entity Model onto a Poco model and the poco gets returned by the service. If my objects have multiple properties, what is a correct way to set-up and then assert my properties? If my service has multiple repo dependencies what is the correct way to setup all my mocks? * - A class [setup] where all the mocks and