repository-pattern

Asp.Net MVC3 adding search functionality

半城伤御伤魂 提交于 2020-01-06 13:08:21
问题 I am trying to implement search functionality on a list of customers, the functionality is detailed in this tutorial on the Asp.Net site, http://www.asp.net/entity-framework/tutorials/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application In my controller i have the following public ViewResult Index(string sortOrder, string searchString) { ViewBag.CustomerNameSortParm = String.IsNullOrEmpty(sortOrder) ? "CustomerName desc" : ""; ViewBag.PrimaryContactNameSortParm

asp.net MVC - How can I share the same instance of a SqlConnection through different repository classes

喜欢而已 提交于 2020-01-04 01:27:31
问题 I'm creating a new project using MVC5 and plain ADO.NET (just as a learning exercise) and I need to create a repository that registers a model with several related objects that also need to be created at the same time and those objects in turn may need to insert other objects. The easiest solution I can think of is to have a massive method(in the repository) that receives an instance of the parent object(which contains all the related objects that needs to insert) and also have a single

asp.net MVC - How can I share the same instance of a SqlConnection through different repository classes

孤街浪徒 提交于 2020-01-04 01:27:08
问题 I'm creating a new project using MVC5 and plain ADO.NET (just as a learning exercise) and I need to create a repository that registers a model with several related objects that also need to be created at the same time and those objects in turn may need to insert other objects. The easiest solution I can think of is to have a massive method(in the repository) that receives an instance of the parent object(which contains all the related objects that needs to insert) and also have a single

How to solve this generic with repository pattern problem?

℡╲_俬逩灬. 提交于 2020-01-03 17:26:17
问题 I had this code from a previous question, but its not compiling: public interface IEntity { // Common to all Data Objects } public interface ICustomer : IEntity { // Specific data for a customer } public interface IRepository<T, TID> : IDisposable where T : IEntity { T Get(TID key); IList<T> GetAll(); void Save (T entity); T Update (T entity); // Common data will be added here } public class Repository<T, TID> : IRepository { // Implementation of the generic repository } public interface

Register all the services at once using Default DI Container from ASP.NET 5 similar to Autofac

两盒软妹~` 提交于 2020-01-03 14:28:15
问题 With ASP.NET 5, there's already a DI shipped as default and it looks interesting. I have been using Autofac with MVC 5 which has the option to register all the assembly at once. Here is a sample code that register all the classes that ends with "Service" in Autofac. // Autofac Configuration for API var builder = new ContainerBuilder(); builder.RegisterModule(new ServiceModule()); ... ... builder.RegisterAssemblyTypes(Assembly.Load("IMS.Service")) .Where(t => t.Name.EndsWith("Service"))

Register all the services at once using Default DI Container from ASP.NET 5 similar to Autofac

梦想的初衷 提交于 2020-01-03 14:28:08
问题 With ASP.NET 5, there's already a DI shipped as default and it looks interesting. I have been using Autofac with MVC 5 which has the option to register all the assembly at once. Here is a sample code that register all the classes that ends with "Service" in Autofac. // Autofac Configuration for API var builder = new ContainerBuilder(); builder.RegisterModule(new ServiceModule()); ... ... builder.RegisterAssemblyTypes(Assembly.Load("IMS.Service")) .Where(t => t.Name.EndsWith("Service"))

Help with EF Code first connection string

与世无争的帅哥 提交于 2020-01-03 03:38:10
问题 Im trying to implement a UnitofWork pattern using this Scott Allen tutorial My current SqlUnitOfWork is the folowing public class SqlUnitOfWork : IUnitOfWork { public SqlUnitOfWork() { var connectionString = ConfigurationManager .ConnectionStrings[ConnectionStringName] .ConnectionString; _context = new ObjectContext(connectionString); _context.ContextOptions.LazyLoadingEnabled = true; } public IRepository<PhysicalTest> PhysicalTests { get { if (_physicalTests == null) { _physicalTests = new

What are the advantages to the Generic Repository Pattern + UOW Pattern with an ORM like Entity Framework [closed]

一个人想着一个人 提交于 2020-01-02 06:00:09
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Let's start with two quotes that sums this issue up: "Wrapping up DbContext is a leaky abstraction. No matter what, you'll end up in

What are the advantages to the Generic Repository Pattern + UOW Pattern with an ORM like Entity Framework [closed]

﹥>﹥吖頭↗ 提交于 2020-01-02 05:59:23
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Let's start with two quotes that sums this issue up: "Wrapping up DbContext is a leaky abstraction. No matter what, you'll end up in

Repository pattern with generics and DI

馋奶兔 提交于 2020-01-01 19:50:50
问题 I have a base repository contract which other contracts extend, like follows public interface IBaseRepository<T> where T : class { IList<T> GetContents(); } and then there are other contracts which extend it like follows public interface IRepository1 : IBaseRepository<MyClass1> { } public interface IRepository2 : IBaseRepository<MyClass2> { } I implement IRepository1 as follows public class Repository1 : IRepository1 { public IList<MyClass1> GetContents() { //some code goes here } } similarly