English 中文(简体)
结构问题
原标题:Question on Structure

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.

我走的路对吗?

请开导我。

非常感谢。

最佳回答

考虑在存储库层定义这些类。从本质上讲,它们是DTO课程,听起来就像你在我本该走的轨道上。

为什么您希望将该类重新映射到其他ViewModel类?

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

//Repo
public IEnumerable<EmpPosition> GetEmployeePositions()
{}
问题回答

暂无回答




相关问题
Mock testing with Repository pattern example

I m refactoring existing class to support Products import from CSV file.   Requirements: 1) during import products are identified by special product number. 2) product has category attribute. ...

Entity Framework using Generic Predicates

I use DTO s to map between my Business and Entity Framework layer via the Repository Pattern. A Standard call would look like public IClassDTO Fetch(Guid id) { var query = from s in _db.Base....

Create, Approve, Edit, Approve pattern for site content

I m working on a modification to a site to allowing users to enter content. However, once they ve created that content it needs to be approved before it can be published. This is fairly easy to ...

Repository + NHibernate + DTO

I have an application with a repository layer (and a nhibernate implementation), service (bussiness) layer, and an asp.net mvc in the web layer. Because I also need to create a small silverlight ...

Organizing classes using the repository design pattern

I have started upgrading one of our internal software applications, written in ASP.NET Web Forms, and moving to ASP.NET MVC. I am trying to leverage the Repository design pattern for my classes, ...

热门标签