repository-pattern

Repository Pattern: how to Lazy Load? or, Should I split this Aggregate?

I have a domain model that has the concept of an Editor and a Project. An Editor owns a number of Projects, and a Project has not only an Editor owner, but also a number of Editor members. Therefore, an Editor also has a number of "joined" Projects. I am taking a DDD approach to modelling this and using the Repository pattern for pers...

Linq to Sql and the Repository Pattern.

I feel like I'm running around in circles. I can't seem to make up my mind as to what the right Repository pattern is using Linq To Sql. If you're familiar with Rob Conery's MVC Storefront you will see that his implementation wraps the Linq-Generated models with another class and treats the Linq-Generated one simply as a Data Transfer Ob...

IRepository confusion on objects returned

I have some e-commerce code that I use often that uses Linq To SQL for saving orders to the database. I want to remove the tightly coupled Linq to SQL bit and pass in an IRepository instead but I am still a little confused on things. Say I have a GetCustomer() method on my ICustomerRepository that returns a Customer object. Do I need...

Repository Pattern and Item Deletion when using SQL Backend

So lets say I have a class called Post that contains an IList I find that it's quite easy to cope with adding of Comments to the list when I ask my repository to update my post it can see which comments are new and send down to my data layer the required information, but what about when a comment is deleted? How do you handle this? Wo...

Transactions in the Repository Pattern

How do I encapsulate the saving of more than one entity in a transactional manner using the repository pattern? For example, what if I wanted to add an order and update the customer status based on that order creation, but only do so if the order completed successfully? Keep in mind that for this example, orders are not a collection in...

Repository Pattern: What is the 'right size'?

I'm building some repositories for an MVC application, and I'm trying to come up with the right way to divide responsibilities between repositories. In most cases, this is obvious. But there is one particular case where I'm not sure what the right answer is. The users of this application need to track multiple types of time for their em...

Repository, Entity objects and Domain Objects

In my Repositories, I am making assignments to my domain objects from the Linq Entity queries. I then have a service layer to act on these object returned from repositories. Should my Domain objects be in the repository like this? Or should my repositories be restricted to the Entities and Data Access, and instead have my service layer...

Is it ok to set Datacontext as a property in repository?

Is there any potential problem in setting datacontext as property like this: repository public Repository() { public DataContext dc {get;set;} public GetOrders(int id) { ...from dc.Orders...} } service layer: public GetNewOrders() { .... Repository rep=new Repository(); using {DataContext dc=...

Does data encryption belong inside the repository pattern?

I'm using application level encryption to protect sensitive data. I need to encrypt the field before I store it in the physical database and I need to decrypt it before I show it on the user interface. I'm applying the Repository pattern in the application. Does the data encryption/decryption code belong inside or outside the Repositor...

Ad hoc data and repository pattern

What is the recommended way to return ad hoc (custom case by case) data from repository which don't fit any model entities or which extend some? The 101 example would be the ubiquitous hello word application: a blog system. Suppose you want to load a list of posts where post entry has some additional information which does not exists in...

Is the Repository Pattern the same as the Asp.net Provider Model?

Since Asp.net 2.0, there is the Provider Model. On the implementation detail, a provider is class derived from ProviderBase which is an abstract class rather than an interface, but anyway the Provider Model is there so that we can have different implementation to swap in the out by just editing the web.config. For example if you create...

Repository Pattern question - is it acceptable to use a repo inside of a different repository?

So I have a repository for basically each entity but my model has a relational division where entities aren't directly related in the model. So what I need to do is query off of that indirect relationship and return a collection of entities. Is it appropriate to initialize and invoke queries on a different repository from the one you are...

Domain Driven Design (Linq to SQL) - How do you delete parts of an aggregate?

Hi All I seem to have gotten myself into a bit of a confusion of this whole DDD\LinqToSql business. I am building a system using POCOS and linq to sql and I have repositories for the aggregate roots. So, for example if you had the classes Order->OrderLine you have a repository for Order but not OrderLine as Order is the root of the aggre...

C# How to convert an Expression<Func<SomeType>> to an Expression<Func<OtherType>>

I have used C# expressions before based on lamdas, but I have no experience composing them by hand. Given an Expression<Func<SomeType, bool>> originalPredicate, I want to create an Expression<Func<OtherType, bool>> translatedPredicate. In this case SomeType and OtherType have the same fields, but they are not related (no inheritance and...

Call methods between repositories - Repository Pattern

Hi, I'm using the Repository Pattern (like the examples in the http://www.asp.net/mvc site) in a ASP.NET MVC application. I have two repositories, one called CategoryRepository an other called ProductRepository. I also use two services, the CategoryService and ProductService to validate and call the repositories methods. I need a list of...

Using Transactions with Business Processes and the Repository pattern

I have a situation (I'm guessing is pretty standard) where I need to perform some business calculations and create a bunch of records in the database. If anything goes wrong at any point I need to roll everything back from the database. Obviosly I need some kind of transaction. My question is where do I implement transaction support. Her...

How do I save an entity for the first time that requires another pre-existing entity to be attached to it

I need to save a Company entity to the database as a new entity. In order to do this I need to associate a CompanyType entity to the Company entity. I can't save the Company without do this. Do I attach the newly created company to the context and then attach the company type entity to the company and then save my results? This code ...

Entity Framework Generic Repository Error

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 pul...

webservices with repository pattern in c# and WCF?

Hi there, Can anyone confirm the best way to integrate the repository pattern with webservices.... Well actually i have my repository patter working now in c#. I have 3 projects, DataAccess, Services and my presentation layer. Problem is my presentation layer is a number of things... I have a ASP.NET MVC site, I have an WPF application...

Repository Pattern with 2 services & 2 dataccess layers - C# DDD?

Can anyone help, I have 2 applications and they are nearly identical. they have a completely different presentation layer (web) and the business logic and database are nearly identical. Basically one app has some things that the other doesn't. so i was wondering if i can do the following without breaking any rules etc Each app has thei...