结构问题

发布于 2024-09-26 21:38:11 字数 406 浏览 12 评论 0原文

我有一个 ASP.NET MVC 2 项目。我已经解耦了各层。我有一个服务层和一个存储库层。 控制器调用服务方法,只有服务层调用存储库中的方法。

问题是: 我的存储库类中的一个方法使用 LINQ 连接。从这个方法中,我想返回一个合并连接表中的一些数据的类型。 (即,Name = a.Name,Position = b.Position)并且我总是在我的存储库类中返回 IEnumerables。所以在这种情况下,我似乎需要为 (Name, Position) 定义一个新类型,并从存储库函数返回该类型。但是,然后,我必须将该类重新映射到其他一些 ViewModel 类。 (因为我正在分离关注点,所以我不应该在存储库中使用视图模型类,对吗?)这会导致许多不同的类。 EF 类、连接表类和视图模型类。

我走的路正确吗?

请赐教。

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

洒一地阳光 2024-10-03 21:38:11

考虑在存储库层定义这些类。本质上,它们是 DTO 课程,听起来你就在我参加的课程中。

您期望将该类重新映射到其他 ViewModel 类的原因是什么?

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

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

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()
{}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文