repository-pattern

Repository Pattern in Layered Architecture

一个人想着一个人 提交于 2019-12-04 15:11:25
I've gone through quite a few articles on the repository pattern and had some questions. I'm trying to implement this in a ASP.NET 4.0 application. The architecture is a layered architecture with a Presentation Layer, Business Layer and Data Layer. From this article, http://www.primaryobjects.com/CMS/Article108.aspx I have created the MYSQLRepository (DataLayer) public class MySQLRepository:IOrderRepository { public List<Order> GetOrders() { List<Order> orders = new List<Order>(); orders.Add(new Order(1,"A")); orders.Add(new Order(2,"B")); return orders; } } My Business Layer looks like this

webservices with repository pattern in c# and WCF?

为君一笑 提交于 2019-12-04 15:05:04
问题 Can anyone confirm the best way to integrate the repository pattern with webservices.... Well actually i have my repository patter working now in c#. I have 3 projects, DataAccess, Services and my presentation layer. Problem is my presentation layer is a number of things... I have a ASP.NET MVC site, I have an WPF application and we are about to create another site + an external company needs access to our repository also. Currently i have just added the services layer as reference to each of

Repository Pattern Retrieve Desired Columns Only

拥有回忆 提交于 2019-12-04 14:12:19
I am using the example here to create a repository pattern with Unit of Work. Within the code, there is a generic Get method: public class GenericRepository<TEntity> where TEntity : class { internal AdminDbContext context; internal DbSet<TEntity> dbSet; public GenericRepository(AdminDbContext context) { this.context = context; this.dbSet = context.Set<TEntity>(); } public virtual IEnumerable<TEntity> Get( Expression<Func<TEntity, bool>> filter = null, Func<TEntity, TEntity> selector = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = "") {

Service Layer/Repository Pattern

南楼画角 提交于 2019-12-04 13:58:14
问题 I am building an MVC app using the Service Layer/Repository/Unit of Work pattern with EF4. I am a bit confused on the logic. I know the point is to decouple the system, but I am a little confused. So the MVC Controllers call on the Services to fill the View Models. So is it safe to say the MVC App is coupled to the Service Layer? Then the Service Layer calls on the Repository to get and persist objects. Is then safe to say the Service Layer is dependent to the Repository? The Repository the

Good repository pattern for asp.net mvc

北战南征 提交于 2019-12-04 13:28:45
I have implemented a repository pattern in my asp.net mvc web application... But i want to know is this a good repository pattern or still can i improve it more... using System; using System.Collections.Generic; using System.Linq; using System.Web; using TaxiMVC.BusinessObjects; namespace TaxiMVC.Models { public class ClientRepository { private TaxiDataContext taxidb = new TaxiDataContext(); Client cli = new Client(); //Get all Clients public IQueryable<ClientBO> FindAllClients(int userId) { var client = from c in taxidb.Clients where c.CreatedBy == userId && c.IsDeleted == 0 select new

DDD/CQRS confusion regarding ReadModels and the Domain

寵の児 提交于 2019-12-04 13:12:35
So after much reading I've now come to the realization that complex reporting functions do not belong in your typical Repository and that there needs to be some kind of dedicated "Finder" which returns read only objects to be used in reporting. What I'm unclear on is where the "Finder" classes, as well as their associated ReadModel classes are supposed to go inside my project? Are the finders like repositories in that you have an interface for the finder inside the infrastructure assembly along with concrete Readmodels? Where do these classes belong? I usually have a logical query 'layer'.

Should we use Data Repository pattern in MVC application using Entity Framework Code First approach?

不想你离开。 提交于 2019-12-04 12:37:20
I have developed many application now with Entity Framework Code First approach. In all of the I use Data Repository pattern. This Data Repository pattern queries over single entity at a Time. for e.g, I have 2 models Employee and Department So to fetch all employees and department I would create 2 data repository instances. e.g var empRepository = new DataRepository<Employee>(); var allEmployees = empRepository.GetAll(); var depRepository = new DataRepository<Department>(); var alldepartment = depRepository.GetAll(); Now, This pattern works great in most of the case. Now, When I want to

Generics and Entity Framework: How do I return a different type depending on a column value

心不动则不痛 提交于 2019-12-04 12:31:18
We have a Persons table which stores different types of persons (Buyer, Seller, Agent, etc). Our ORM is Entity Framework CodeFirst (CTP5). We're using the repository pattern for good TDD and mocking. In the PersonRepository I want to return a specific type so I can do things like this: Agent a = repository.Get<Agent>(5005); // Where 5005 is just an example Id for the person a.SomeAgentProperty = someValue; Buyer b = repository.Get<Buyer>(253); // Again, a simple PersonId. b.SomeBuyerProperty = someOtherValue; The idea is that I know what kind of person I'm getting when I get it from the

ASP.NET MVC - Should I use the Repository Pattern to write ViewModels to the database or convert them to Models first?

喜夏-厌秋 提交于 2019-12-04 11:50:34
问题 In my ASP.NET MVC app, I have a fairly complex edit page which combines a number of models into one view. I'm using the ViewModel pattern to combine all of this information and present one cohesive object to the View. As an example, my ViewModel structure is something like this: CompanyId CompanyName List<Employee> Employees List<ContactMethod> ContactMethods The Employee object has a number of basic properties, and a preferred contact method. On the edit page, the user is given all of the

UOW + Repository + Autofac load two different DbContext

我的未来我决定 提交于 2019-12-04 11:46:35
I'm facing an issue today and I'm unable to solve it, I searched a lot and can't get into a solution, please help me if you can. I'm implementing a MVC application which uses EF + Repository Pattern + Unit Of Work with Autofac as the Dependency Injector. I was able to work with one DbContext class, but I'm facing a situation where I need to use another DbContext instance (which access another database with another user credentials) Let me explain better: I have EntityA which comes from database A (and have a DatabaseA_Context class). So I need a EntityB, which comes from database B (with its