repository-pattern

Looking for a code sample or "template" for an EF Repository

I'm looking for a good Entity Framework repository code sample or template. ...

Repository Pattern - POCOs or IQueryable?

Hi 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: pu...

My code is riddled with service interfaces!

Hey all. I'm coming across a weird design pattern using the repository and service model. The application constists of ASP.NET MVC, WCF, and some Windows services. My repositories are using LINQ DataContext. As my application evolves I'm finding myself passing references to IWhateverService service everywhere. For example, I have IA...

TDD-friendly Singleton-like class

I have repository class that is used by at least 2 other classes. This repository class needs to be initialized - which is high in cost (querying database). Now, I create separate instances of repository wherever I need it. The thing is, that everytime I create repository it has to be initialized. How to design such repository to be TDD-...

Is a Repository still a Repository without Unit of Work?

If you create a repository class that encapsulates all of your persistence logic for a given entity, such as PersonRepository, but your repository class does not implement the Unit of Work pattern or the Identity Map pattern, is it still considered a repository? In other words, are Unit of Work and Identity Map required for a repository...

Is it ok for entities to access repositories?

I've just started working with DDD, so maybe this is a silly question... Is it ok for an entity to access a repository (via some IRepository interface) to get a value at runtime? For example, I want to enforce a "default" selection for a property: class Person { private Company _employer; public Company Employer { get...

Linq to SQL and concurrency with Rob Conery repository pattern

I have implemented a DAL using Rob Conery's spin on the repository pattern (from the MVC Storefront project) where I map database objects to domain objects using Linq and use Linq to SQL to actually get the data. This is all working wonderfully giving me the full control over the shape of my domain objects that I want, but I have hit a ...

What are the pros/cons of returning POCO objects from a Repository rathen than EF Entities?

Following the way Rob does it, I have the classes that are generated by the Linq to SQL wizard, and then a copy of those classes that are POCOs. In my repositories I return these POCOs rather than the Linq to SQL models: return from c in DataContext.Customer where c.ID == id select new MyPocoModels.Customer { ID = c.ID, ...

Repository in Controller or Model?

I've been working through the NerdDinner Tutorial and most of it makes sense. What I'm not sure about is why the Repository is used directly in the Controller and not the Model objects. For instance, if we wanted to implement our own membership system and it had an AccountController with a Login method, what would be the best solution fo...

C# Linq-SQL: An UpdateByID method for the Repository Pattern

I have implemented a sort of Repository class and it has has GetByID, DeleteByID methods and so on, but I'm having trouble implementing the UpdateByID method. I did something like this: public virtual void UpdateByID(int id, T entity) { var dbcontext = DB; var item = GetByID(dbcontext, id); item = entity; ...

Automapper for use with Entity Framework using repository pattern?

Hi there, Been busy creating a new app, basically i have my dataccess, service layer and presentation layer... All works great but i am using the entity classes that are returned by EF. Problem here is i pass these onto the presentation layer so i need to add the entity framework reference /dataccess to the presentation layer - NOT GOOD...

Repository pattern vs. "smart" business objects

I see two main "schools of thoughts" when it comes to creating larger-scale enterprise-wide apps on .NET (Winforms, WPF, ASP.NET). Some folks use the "repository pattern" which uses a repository that knows how to fetch, insert, update and delete objects. Those objects are rather "dumb" in that they don't necessarily contain a whole lot ...

Exceptions inside repositories: how do you handle them?

An easy one that I am interested in getting your thoughts on: With your repository implementations, do you like to let exceptions be thrown inside the repository and leave the exception handling to the caller, or do you prefer to catch exceptions inside your repository, store the exception and return false/null? ...

How to implement Repository Pattern with interface, base and concrete.

I have almost completed implementing my repository pattern by having a IRepository<T> interface, a NewsRepository class and a News entity. The problem I ran into was trying to abstract out common methods to a base Repository class. I could not find a way to abstract the Get method in the NewsRepository as it contains a specific Linq ex...

Issues with my MVC repository pattern and StructureMap

I have a repository pattern i created on top of the ado.net entity framework. When i tried to implement StructureMap to decouple my objects, i kept getting StackOverflowException (infinite loop?). Here is what the pattern looks like: IEntityRepository where TEntity : class Defines basic CRUD members MyEntityRepository : IEntityReposito...

Using nHibernate, how do you lay out your files in a VS.NET solution?

Using nHibernate, (and the repository pattern), how do you go about laying out your files/folder? I am going to to DDD, and use the repository pattern so I will have lots of classes that map to my database tables, and lots of repositories that inherit from an interface etc. Something like: /root/ /root/web.config /root/class/user.cs ....

Advice on passing criteria information to service call.

I have a repository that has several specifications available. For Ex. I can call: EmployeeRepository.EmployeeSpecification().ForRegion("West Coast").Executives().OrderByLastName().OrderByFirstName().Page(1, 10). This will return me a result package containing the results array and metadata created by the specifications such as how many ...

TDD - Want to test my Service Layer with a fake Repository, but how?

Hello, I've designed an application that uses the repository pattern, and then a separate service layer such as this: public class RegistrationService: IRegistrationService { public void Register(User user) { IRepository<User> userRepository = new UserRepository(); // add user, etc } } As you can see, I...

Repository pattern and data type returned...

I am using the repository pattern and was wondering about what data type I should return. In my database I have a string that is variable length that needs to be broken up based off of fixed lengths. I was initially thinking of passing out the string and letting the service layer do the parsing based on the lengths of the configured co...

How much logic should i put my repository methods when using repository pattern?

Hi, i'm struggling a bit with repositories. I'm using C# and NHibernate. The question i have is : how much should my repository do before it calls a save or a get? For example i have a user class which is an aggregate root. I want to call a method called "register" which will add the user and set some default values based on business ...