views:

20

answers:

1

Hi all, I've read a lot about repository pattern implementation and I still can't find out how should I implement entity projections querying?

For example I have large and complex product entity, but I want to display only product's name and it's id. Where should i implement this projection? In my entity repository or in a caller code?

A: 

I do this in the repository.

For instance, my ProductRepository interface would look like this:

interface IProductRepository
{
    Product Get( int productId );

    void Save( Product product );

    ProductView FindProducts(string productNameSearch);
}

Where ProductView is a simplified representation of Product. (Only containing name and id for instance).

The projection to get a ProductView, is something that has to be abstracted away, and the repository is a good place for it, imho.

Frederik Gheysels
But don't you break the repository pattern this way, as this pattern is intended to provide collection-like access to entities, not entity views?
innerJL