repository-pattern

How do I handle table relationships with the repository pattern?

假如想象 提交于 2019-12-03 06:38:10
I'm implementing the repository pattern as part of an ASP.NET MVC site. Most examples I've seen of repositories are fairly simple. For example here's a typical abstract repository interface. public interface IRepository<TEntity> { IQueryable<TEntity> All(); TEntity FindBy(int id); TEntity FindBy(Expression<Func<TEntity, bool>> expression); IQueryable<TEntity> FilterBy(Expression<Func<TEntity, bool>> expression); bool Add(TEntity entity); bool Update(TEntity entity); bool Delete(TEntity entity): } It's clear to me how you would use a repository like this to add, update, delete, or get entities

Disposing of object context in entity framework 4

泄露秘密 提交于 2019-12-03 06:14:04
问题 I have an entity class which is auto generated from my database model. This class inherits the ObjectContext which inturn inherits IDisposable. I have created a repository that has various methods which use a single instance of the entity object to interact with the database. Auto generated class public partial class DevEntities : ObjectContext { public const string ConnectionString = "name=DevEntities"; public const string ContainerName = "DevEntities"; Repository Class DevEntities db = new

Repository Pattern - POCOs or IQueryable?

匆匆过客 提交于 2019-12-03 05:52:00
I'm new to the Repository Pattern and after doing a lot of reading on the web I have a rough understanding of what is going on, but there seems to be a conflict of ideas. One is what the IRepository should return. I would like to deal in ONLY Pocos so I would have an IRepository implementation for every aggregate root, like so: public class OrangeRepository: IOrangeRepository { public Orange GetOrange(IOrangeCriteria criteria); } where IOrangeCriteria takes a number of arguments specific to finding an Orange. The other thing I have is a number of data back-ends - this is why I got into this

Using multiple DbContexts with a generic repository and unit of work

坚强是说给别人听的谎言 提交于 2019-12-03 05:23:44
问题 My application is getting larger and so far I have a single MyDbContext which has all the tables I need in my application. I wish (for the sake of overview) to split them up into multiple DbContext , like MainDbContext , EstateModuleDbContext , AnotherModuleDbContext and UserDbContext . I am unsure how this is done probably as I am right now using dependecy injection (ninject) to place my DbContext on my UnitOfWork class like: kernel.Bind(typeof(IUnitOfWork)).To(typeof(UnitOfWork<MyDbContext>

Pattern for retrieving complex object graphs with Repository Pattern with Entity Framework

孤街醉人 提交于 2019-12-03 05:12:09
问题 We have an ASP.NET MVC site that uses Entity Framework abstractions with Repository and UnitOfWork patterns. What I'm wondering is how others have implemented navigation of complex object graphs with these patterns. Let me give an example from one of our controllers: var model = new EligibilityViewModel { Country = person.Pathway.Country.Name, Pathway = person.Pathway.Name, Answers = person.Answers.ToList(), ScoreResult = new ScoreResult(person.Score.Value), DpaText = person.Pathway.Country

Practical usage of the Unit Of Work & Repository patterns

邮差的信 提交于 2019-12-03 05:04:22
问题 I'm building an ORM, and try to find out what are the exact responsibilities of each pattern. Let's say I want to transfer money between two accounts, using the Unit Of Work to manage the updates in a single database transaction. Is the following approach correct? Get them from the Repository Attach them to my Unit Of Work Do the business transaction & commit? Example: from = acccountRepository.find(fromAccountId); to = accountRepository.find(toAccountId); unitOfWork.attach(from); unitOfWork

Repository Pattern and multiple related core entities or business objects - one repository or more?

拟墨画扇 提交于 2019-12-03 04:23:17
问题 I am looking at implementing the repository pattern (since what I came up with was 90% an implementation of it anyway), and have come across a design question - where I have two or more core business objects (for example, Business and Contact in a CRM app), the BO's can be strongly related or not related at all. In this situation, should I implement one repository (CrmRepository for example, with .addBusiness(), .addContact() et al), or multiple repositories (BusinessRepository,

How to design a Repository Pattern with Dependency Injection in ASP.NET Core MVC?

时光毁灭记忆、已成空白 提交于 2019-12-03 03:47:28
问题 Being fairly new to ASP.NET Core 1.0 MVC, I have decided to use a Repository Pattern for an MVC Core app; I'm using a SQL DB for the Data Layer SampleDbContext , and I want to have a Repository class for some of my business Entities. So far I have done the following in the startup.cs , CustomerController.cs and CustomerRepository.cs files, where a sample Entity is "Customer". In the ConfigureServices method of the Startup Class: public void ConfigureServices(IServiceCollection services) {

I need some clarification on the MVC architecture and the three-tier architecture

試著忘記壹切 提交于 2019-12-03 03:27:39
I've been reading the book Pro ASP NET MVC Framework and I'm getting really confused with a lot of things. I've been trying to do some research but I'm finding that with so many different approaches and concepts being thrown at me, it's just making things worse. So I have a few questions: I know MVC is supposed to split the functionality into three main things: Model -> Controller -> View. Is the MVC a different approach than the three-tier architecture? Or am I still supposed to be thinking of creating a Data Access Layer and a Business Logic Layer in my project? What exactly are Repositories

Using a Generic Repository pattern with fluent nHibernate

谁说我不能喝 提交于 2019-12-03 03:21:39
问题 I'm currently developing a medium sized application, which will access 2 or more SQL databases, on different sites etc... I am considering using something similar to this: http://mikehadlow.blogspot.com/2008/03/using-irepository-pattern-with-linq-to.html However, I want to use fluent nHibernate, in place of Linq-to-SQL (and of course nHibernate.Linq) Is this viable? How would I go about configuring this? Where would my mapping definitions go etc...? This application will eventually have many