repository-pattern

Where should I create the Unit of Work instance in an ASP.Net MVC 3 application?

允我心安 提交于 2019-12-03 10:12:15
问题 I have read as many of the posts on Stackoverflow as I can find with regards the use of a Unit of Work pattern within an ASP.Net MVC 3 application which includes a Business Layer. However, I still have a couple of questions with regards this topic and would greatly appreciate any feedback people can give me. I am developing an ASP.Net MVC 3 Web application which uses EF 4.1. I will be using both the Repository and Unit of Work Patterns with this project similar to how they are used in this

There is no argument given that corresponds to the required formal parameter 'context of GenericRepository<Incident>.GenericRepository(dbContext)

十年热恋 提交于 2019-12-03 10:06:13
I am getting this error message which when trying to inherit from my GenericRepository. The error says I need to also provide a context but I am not sure how? //IncidentRepository public class IncidentRepository : GenericRepository<Incident> //Generic Repository (to inherit from) public class GenericRepository<TEntity> where TEntity : class { internal db_SLee_FYPContext context; internal DbSet<TEntity> dbSet; public GenericRepository(db_SLee_FYPContext context) { this.context = context; this.dbSet = context.Set<TEntity>(); } EDIT: Just to check I've grasped this? public class

Controller -> Service -> Repository: Does service map Entity to ViewModel?

坚强是说给别人听的谎言 提交于 2019-12-03 09:51:25
问题 I haven MVC app, with "M" including Service and Repository layers. However, I am a little confused as to where and how to do a couple of things. One Service calling two repositories, or calling it's own repository and another service e.g. I have a ReferenceDataService, which handles all of the logic for CRUD with my reference tables. Then in my "CustomerService" I need to 'R' my reference data to get e.g. Description instead of Id. So, do I call the ReferenceDataService or

How would I design a repository to handle multiple data access strategies?

无人久伴 提交于 2019-12-03 09:10:45
What would a skeleton design look like for a repository able to support multiple database layers using ASP.NET MVC and C#? I want to see what a design would look like if I support both LINQ to SQL and NHibernate. How would I create my database object, and call a method on it in my BLL layer? The repository pattern is probably the best solution for this. You would define an interface for each repository, then create concrete repositories for Linq2Sql and NHibernate implementations, e.g. public interface ICustomerRepository { Customer GetCustomer(int id); } public class NhibCustomerRepository :

IRepository confusion on objects returned

北城以北 提交于 2019-12-03 09:09:28
I have some e-commerce code that I use often that uses Linq To SQL for saving orders to the database. I want to remove the tightly coupled Linq to SQL bit and pass in an IRepository instead but I am still a little confused on things. Say I have a GetCustomer() method on my ICustomerRepository that returns a Customer object. Do I need it to really return an ICustomer object that gets passed back from that method so if I switch from Linq To SQL to say SubSonic it's not a problem? I believe I do, if that is the case is there a way in Linq To SQL to easily convert my Linq To SQL Customer object to

Service Layer/Repository Pattern

烈酒焚心 提交于 2019-12-03 08:46:30
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 utilizes EF4 to get and persist data to SQL server, so I would assume the Repository depends on EF4

webservices with repository pattern in c# and WCF?

江枫思渺然 提交于 2019-12-03 08:35:25
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 the sites... But is not the normal way to provide data access via web services? (WCF) - if this is the

How to map Entity Framework model classes with Business Layer class in n-tier architecture - ASP.NET-MVC

隐身守侯 提交于 2019-12-03 08:31:48
I am working on e-tier architecture within MVC framework (ASP.NET MVC5, Entity Framework 6). My application is divided into three sub-projects which are Business-Layer, Data-Access-Layer, Repository (This include repository and Unit of Work) and ASP.NET MVC web-app. I am struggling to understand mapping between business data and entity framework model. for example if I have model class User in entity framework as DAL - User Model [Table("User")] public class User { public User() { } [Key] public int UserID { get; set; } [StringLength(250)] [Required] public string FirstName { get; set; }

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

不羁岁月 提交于 2019-12-03 07:28:46
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 employees of the company and they have the ability to add and remove (using javascript), as well as edit

Entity Framework Generic Repository Error

旧城冷巷雨未停 提交于 2019-12-03 07:26:11
问题 I am trying to create a very generic generics repository for my Entity Framework repository that has the basic CRUD statements and uses an Interface. I have hit a brick wall head first and been knocked over. Here is my code, written in a console application, using a Entity Framework Model, with a table named Hurl. Simply trying to pull back the object by its ID. Here is the full application code. using System; using System.Collections.Generic; using System.Linq; using System.Text; using