repository-pattern

Repository pattern with Entity Frameworks 4

I used to use NHibernate with repository interfaces. What is the proper way to use this pattern with EF? How can I implement this repository interface, for a RepositoryBase<T>? public interface IRepository<T> { T GetById(object id); void Save(T entity); T[] GetAll(); void Delete(T entity); } ...

Repository Pattern in asp.net mvc with linq to sql

I have been reading though the code of the NerdDinner app and specifically the Repository Pattern... I have one simple question though, regarding this block public DinnersController() : this(new DinnerRepository()) { } public DinnersController(IDinnerRepository repository) { dinnerRepository = repository; ...

DDD: Repositories are in-memory collections of objects?

I've noticed Repository is usually implemented in either of the following ways: Method 1 void Add(object obj); void Remove(object obj); object GetBy(int id); Method 2 void Save(object obj); // Used both for Insert and Update scenarios void Remove(object obj); object GetBy(int id); Method 1 has collection semantics (which is...

Possible to use the Repository Pattern + Stored Procedures ? Should / can they return IQueryable?

Hi folks, I'm a big fan of using the Repository pattern to return IQueryable<T> objects. I then let my services layer determine what does what (eg. filter by XXX, order by YYY, project into ABCD, etc). But I've got some hardcore DB stuff, so I've got it all wrapped up into a Stored Procedure. Works fine. I know EF can execute stored pr...

Linq to SQL using Repository Pattern: Object has no supported translation to SQL

I have been scratching my head all morning behind this but still haven't been able to figure out what might be causing this. I have a composite repository object that references two other repositories. I'm trying to instantiate a Model type in my LINQ query (see first code snippet). public class SqlCommunityRepository : ICommunityRepo...

Entity Framework CTP4 non-standard primary key name usage in BaseEntity

I am struggling already several days to solve my problem with primary key usage. Please, someone help me to solve this puzzle!!! I am using Entity Framework with CTP4 using Code First approach. I adopted for my project Repository pattern published by Huyrua see here. I am very exited with this patern and with CTP4 possibilities in parti...

Updating a Model in asp.net mvc

Our project manager has asked us to refactor an app that was using the Repository Pattern (it was done using Nerddinner as example) to now use a service Layer. My problem now is that Im not sure how to Update a Model cause the UpdateModel method is supposed to be used in the controller... whats a recomended approach to updating a model u...

Any good example on Implementation of spring.net + NHibernate + Repository pattern

Are there any good example on implementation of Spring.net with NHibernate and Repository pattern? Currently I'm going through below url's. http://www.springframework.net/doc-latest/reference/html/orm.html#orm-hibernate-web ...

Is Repository pattern an overkill

I have been using Repository pattern (DDD and POEAA) for some time. However some of our team members have argued that it is just an extra layer of abstraction and unnecessary. I can seen some benefit in their arguments. Modern ORM solutions (NHibernate or EF) have almost everything you need. I searched and found some article like this an...

Repository Pattern

Hello, I've got a quick question regarding the use of repositories. But the best way to ask is to show a bit of pseudocode and you guys tell me what the result should be Get a record from the repository with ID of 1 (assume it exists) Edit a couple of properties Query the repository again for an item with ID of 1 Result = ?? Should ...

Repository Pattern - Caching

Hi community, i'm not sure, where i should implement the caching in my repository pattern. Should I implement it in the service-logic or the repositiory? GUI -> BusinessLogic (Services) -> DataAccess (Repositories) Thanks and best regards ...

How do I write a Func<T, bool> to return the entity with the most children?

I have a repository accessing my Entity Framework. I have a method that looks like this: public TEntity FindOne(Expression<Func<TEntity, bool>> criteria) { var query = _queryAll.Where(criteria); return query.FirstOrDefault(); } I have 2 Entities that have a one to many relation. Lets call them Courses and Students. A Course c...

Does my repository have too much logic?

I have a legacy database that my new application has to interact with. The old database is over-normalized and poorly designed in general. For instance, one object in my domain represents five tables in the database. I want to keep my domain layer free of artifacts from the legacy database. What pattern should I use here? At first glanc...

Is Repository pattern as same as Active Record pattern?

They seems to be similar. ...

LINQ-To-SQL - Is it possible to cache GetTable or serve it from repository?

Hi, I'm running profiler tools on the LINQ-to-SQL data access layer. A lot of the time is spent on GetTable<clsName>() because it's being called each time i CRUD data. Is it possible to cache GetTable<clsName>() for all the tables when the application starts or serve it through some sort of repository where it will be in memory? Th...

Which layer should Repositories go in?

Which layer should the repository classes go in? Domain or Infrastructure? ...

Repository pattern: One repository class for each entity?

Say you have the following entities defined in a LINQ class: Product Customer Category Should I have one repository class for all: StoreRepository ... or should I have: ProductRepository CustomerRepository CategoryRepository What are the pro & cons of each? In my case, I have several "applications" within my solution... the Stor...

POCO + Entity Framework with repository pattern - permission handling

Hello. I have an application that consists of 3 layers: UI: to be implemented in ASP.NET MVC Business: Holds the business logic and resource access control Repository (DAL): Implemented with POCO objects and EF, using the repository pattern. My POCO objects are shared with the upper layers. I have questions about what information/meth...

Asp.net MVC 2 Entity Framework Generic Repository Method. how to Update a specific Collumn

I have 10 tables with the same design. Each of them has an IsActive Collumn. EX: Category CatID CatName IsActive Product PrdID PrdName IsActive Is there a way to create a generic method to update the IsActive column. public void Deactivate<T>(T TEntity) { //Put the code to update //IsActive } I Read ...

Layered Architecture Question

Hello. I am developing an piece of software where I have a few entities such as: public class Workspace { public int ID { get; set; } public string Name { get; set; } public string Description { get; set; } public virtual List<Playground> Playground { get; set; } public virtual List<Workspa...