views:

14

answers:

1

Hi,

I have an ASP.NET MVC 2 project. I've decoupled layers. I have a service layer and a repository layer. The controller calls service methods and only the service layer calls methods in the repository.

The problem is: A method in my repository class uses LINQ joins. From this method, I would like to return a type with merging some data from joined tables. (i.e, Name = a.Name, Position = b.Position) And I always return IEnumerables in my repository class. So in this case, it seems I need to define a new type for (Name, Position), and return that type from the repository function. But, then, I'll have to remap that class to some other ViewModel class. (Because I'm seperating concerns, I shouldnt use viewmodel classes in repository right?) This leads to many different classes. EF classes, classes for joined tables, and viewmodel classes.

Am I in the right path?

Please enlighten me.

Thank you

A: 

Consider defining those classes at the repository layer. Essentially they're DTO classes, and it sounds like you were on the track I'd have taken.

Any reason why you were expecting to remap that class to some other ViewModel class?

public class EmpPosition()
{
    public property Name{get;set;}
    public property Position{get;set;}
}

//Repo
public IEnumerable<EmpPosition> GetEmployeePositions()
{}
p.campbell