repository-pattern

Is It possible to use the second part of this code for repository patterns and generics

Is there any issues in using version 2,to get the same results as version 1. Or is this just bad coding. Any Ideas public class Customer { public int CustomerID { get; set; } public string EmailAddress { get; set; } int Age { get; set; } } public interface ICustomer { void AddNewCustomer(Customer Customer); void A...

Any sample C# project that highlights separate data access layer (using EF) to business logic layer

Hi, I'm interested in having a look at a small sample project that would highlight a good technique to separate data access layer (using Entity Framework) to business logic layer. In C# would be good. That is, it would highlight how to pass data between the layer without coupling them. That is, the assumption here is not to use the E...

Passing an instantiated class to concrete class derived by Castle Windsor

I have a system that I'm using to test some new architecture. I have the following setup (In MVC2 .Net - C Sharp): View < Controller < Service < Repository < DB I'm using Castle Windsor as my DI (IoC) controller, and this is working just fine in both the Service and Repo layers. However, I'm now at a point where I would like to pass an...

Should repositories expose IQueryable to service layer or perform filtering in the implementation?

I'm trying to decide on the best pattern for data access in my MVC application. Currently, having followed the MVC storefront series, I am using repositories, exposing IQueryable to a service layer, which then applies filters. Initially I have been using LINQtoSQL e.g. public interface IMyRepository { IQueryable<MyClass> GetAll(); } ...

What are some good Repository pattern examples for use with Entity Framework 4.0?

Can anyone refer me to good and complete/semi-complete examples of using EF 4 with the Repository pattern? Thanks! ...

How should I structure my repository classes?

I am new to DDD. In my mini-project, I have a structure that looks like this (different from the actual names): EntryClassificationGroup EntryClassification Entry EntryType Should I have just one repository class for all these 4 entities, since they are all related? Or should I have individual repositories for each one? ...

How do I implement repository pattern and unit of work when dealing with multiple data stores?

I have a unique situation where I am building a DDD based system that needs to access both Active Directory and a SQL database as persistence. Initially this wasnt a problem because our design was setup where we had a unit of work that looked like this: public interface IUnitOfWork { void BeginTransaction() void Commit() } and o...

WPF tree data binding model & repository

Hi, I have a well defined tree repository. Where I can rename items, move them up, down, etc. Add new and delete. The data is stored in a table as follows: Index Parent Label Left Right 1 0 root 1 14 2 1 food 2 7 3 2 cake 3 4 4 2 pie ...

EntityFramework repository template- how to write GetByID lamba within a template class?

I am trying to write a generic one-size-fits-most repository pattern template class for an Entity Framework-based project I'm currently working on. The (heavily simplified) interface is: internal interface IRepository<T> where T : class { T GetByID(int id); IEnumerable<T> GetAll(); IEnumerable<T> Query(Func<T, bool> filter); } G...

Repository, Service or Domain object - where does logic belong?

Take this simple, contrived example: UserRepository.GetAllUsers(); UserRepository.GetUserById(); Inevitably, I will have more complex "queries", such as: //returns users where active=true, deleted=false, and confirmed = true GetActiveUsers(); I'm having trouble determining where the responsibility of the repository ends. GetActiveU...

Understanding Domain Driven Design

Hi I have been trying to understand DDD for few weeks now. Its very confusing. I don't understand how I organize my projects. I have lot of questions on UnitOfWork, Repository, Associations and the list goes on... Lets take a simple example. Album and Tracks Album: AlbumId, Name, ListOf Tracks Tracks: TrackId, Name Should i expose...

Migration from linq2sql to EF4.0

In linq2sql I had this code to implement base class for repository public abstract class Repository<T> : IRepository<T> where T : class { protected DataContext context; protected Table<T> table; public Repository (DataContext context) { this.context = context; table = context....

Should repositories use the same context instance within the Entity Framework 1.0

Hello, I have started to look at the Entity Framework for a project I am doing and going down the road of using a BLL against it via the the repository pattern. As I understand it for each entity I should create a repository for it so I would have public class UserRepository : IRepository<User> { ... } and public class AccountReposi...

ASP.NET MVC (MVC2) Best practices when Inserting/Updating Data using Linq to SQL and Repository layers

I'm in a bit of a conundrum here and I'm hoping for some of you Guru's to help fill in the blanks. The situation I'm currently facing is with regards to my "Users" table and my "OpenID" table. My app allows for a user to have multiple OpenID's, so I keep track of them in a separate table. Users ID Username OpenID ID Us...

How I can programmatically retrieve a primary key for an entity (in Entity Framework 4) ?

I have this base abstract class which implements repository pattern public abstract class Repository<T> : IRepository<T> where T : class { private ObjectSet<T> _entitySet; private ObjectContext _dataContext; public Repository(ObjectContext context) { _dataContext = context; _e...

Repository in T4 template

I am writing a T4 template for repositories. Say we have Customers/Orders/Products tables. We then have CustomerRepo, OrdersRepo, and ProductsRepo. Is it a good practice to have a generic repo for all of them? public partial class Repository { private IContext context; public Repository() { _Product = new ProductRepo(); _Cu...

Function Import and Repository pattern with Entity Framework 4.0

Could anyone advise me on how they've implemented the use of Function Imports when using the Repository pattern against EF 4.0? We have a table mapped to a Candidate Entity and also a Function Import off an existing sproc that maps to Candidate. This works great in EF but we're abstracting by use of Repositories which take on their con...

LINQ to SQL not updating database records in MVC 2 application

Hello :) Using MVC 2 I have been trying to make this record store project. Creating records work but updating them doesn't. No exceptions are thrown either. I examined getchangeset() right before submitchanges() it shows all zeros. Thanks for your reading and you help :) The Edit view: <% using (Html.BeginForm("Edit", "Song")) { %> ...

EF - and repository pattern - multiple contexts

I've faced some troubles with context in EF in ASP.MVC2. I thought that best way to improve some operation on DataBase i've created Repository. My repo class adds, deletes, select many items so i don't need to write (using <name>Context = new (... etc ...) ) { ... } Repository eliminates initializing context for every operation, but...

Is it good to introduce nHibernate for a legacy database in an ongoing project?

I am working on a current ongoing project where, there are two instances of the database having different schemas for some of the tables and is being used for transfer from one to another. Database schema is not well defined like, No Primary key for some of the tables Primary key as a composite key Foreign keys in composite primary ke...