repository-pattern

Entity Framework Generic Repository Error

蹲街弑〆低调 提交于 2019-12-02 20:59:37
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 System.Data.Objects; using System.Linq.Expressions; using System.Reflection; using System.Data.Objects

Entity classes decoupled from LINQ to SQL provider for implementing the Repository pattern. How?

谁说我不能喝 提交于 2019-12-02 19:42:07
I have looked over the Repository pattern and I recognized some ideas that I was using in the past which made me feel well. However now I would like to write an application that would use this pattern BUT I WOULD LIKE TO HAVE THE ENTITY CLASSES DECOUPLED from the repository provider. I would create several assemblies : an "Interfaces" assembly which would host common interfaces including the IRepository interface an "Entities" assembly which would host the entity classes such as Product, User, Order and so on. This assembly would be referenced by the "Interfaces" assembly since some methods

Disposing of object context in entity framework 4

不羁岁月 提交于 2019-12-02 19:37:01
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 DevEntities(); public Customer GetCustomerByID(int id) { var customers = db.Customers.FirstOrDefault(c

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

让人想犯罪 __ 提交于 2019-12-02 18:30:33
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.Legal.DPA.Description, DpaQuestions = person.Pathway.Country.Legal.DPA.Questions, Terms = person.Pathway

Using multiple DbContexts with a generic repository and unit of work

非 Y 不嫁゛ 提交于 2019-12-02 17:47:59
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>)); Should I drop this approach with dependency injection and explicit set the DbContext I wish to use

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

你说的曾经没有我的故事 提交于 2019-12-02 17:38:57
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, ContactRepository each with their own .add(), .delete() et al). What is the best practice in this situation? The

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

被刻印的时光 ゝ 提交于 2019-12-02 17:13:22
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) { services.AddDbContext<SampleDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString(

Using a Generic Repository pattern with fluent nHibernate

╄→гoц情女王★ 提交于 2019-12-02 16:51:18
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 facets - from a WebUI, WCF Library and Windows applications / services. Also, for example on a "product

MVC3 App/Service Layer/Repository Layer/POCO Classes/EF4 - Questions!

微笑、不失礼 提交于 2019-12-02 16:47:25
I am new to this whole design concept, and in reading for the last few weeks I have gathered a lot of information, but it seems scattered and conflicted. Terms are mixed, and I am just having a hard time wrapping my mind around this. The pattern I am using is like this and assume the flow as follows: MVC Application The controller(s) process the request/response from the client for a given view. Inside the controllers action methods, they contact the services (Service Layer) and either request objects to build the view models, and sen the objects from the view models back. View Models I am

How can I write a clean Repository without exposing IQueryable to the rest of my application?

拟墨画扇 提交于 2019-12-02 16:47:01
So, I've read all the Q&A's here on SO regarding the subject of whether or not to expose IQueryable to the rest of your project or not (see here , and here ), and I've ultimately decided that I don't want to expose IQueryable to anything but my Model. Because IQueryable is tied to certain persistence implementations I don't like the idea of locking myself into this. Similarly, I'm not sure how good I feel about classes further down the call chain modifying the actual query that aren't in the repository. So, does anyone have any suggestions for how to write a clean and concise Repository