views:

144

answers:

2

I was studying the Oxite project on Codeplex. It has repository interfaces, and an implementation using LINQ to SQL. The LINQ to SQL results are projected to POCO objects in the repository implementations. It looks something like:

public IQueryable<Post> GetPosts()
{
    return projectPosts(excludeNotYetPublished(getPostsQuery(siteID)));
}

This is an interesting pattern, so I wondered if it has a specific name.

Thanks!

+2  A: 

Data Mapper. See it mentioned here http://www.martinfowler.com/eaaCatalog/repository.html

"In such systems it can be worthwhile to build another layer of abstraction over the mapping layer where query construction code is concentrated".

Note that there are different views on this. I would say those that subscribe to doing that, claim the linq2sql classes are specific to the data access technology, so I guess they see it as an implementation detail of the repository.

Perhaps you mean to ask for a name on the "repository" that returns an IQueryable. I don't think there is a commonly agreed name for that one. Rob Connery used this one on his asp.net mvc storefront series: http://blog.wekeroad.com/mvc-storefront. If you look at the old blog posts on it, you can see calling a repository is actually controversial.

eglasius
It takes some glue code to map LINQ to SQL classes (specific to the data access technology in my view) to POCO's. Also, I feel that since IQueryable<T> and Expression<T> are part of the BCL, they will in time become part of the design patterns (repository and specification). Thanks!
michielvoo
+1  A: 

I think this is more of the Data Transfer Object (DTO) pattern, where results are turned into a DTO for transfer across layers. See Data Transfer Object.

John Saunders
@John not really, with the quoted approach the returned objects are the domain objects.
eglasius
Sorry, I don't understand, which "quoted approach". In the case of DTO, the objects are not domain objects, but DTO objects carrying the data to or from the domain objects. Their structure parallels the domain objects, but they have no behavior, just data.
John Saunders
I meant the approach that michielvoo posted on the question. In the example above, Post is a domain objects (not a DTO). Although you might be meaning that linq2sql classes are the DTO?
eglasius