将 CustomMembershipUser 和 Agregate 类存储在域库中是否合适
我只需要一些确认,证明我以正确的方式做了一些事情,否则我会犯可怕的错误:)
1)我将数据访问层(MyProject.Domain)放在单独的程序集中。在那里,我有实体对象“User”,其属性与数据库中的“User”表具有 1:1 关系。我还从“MembershipUser”扩展了此用户,因为我使用自定义架构作为成员资格。这是存储 MembershipUser 实体的好位置吗?
2)我的数据库中有“图像”表,域库中有“图像”实体。数据库中的图像具有“AuthorId”列,该列是“User”表的 FK。图像还包含“评论”列表。所以我像这样构造 Image 域对象:
public class Domain
{
public int ImageId{get;set;}
public string Name{get;set;}
public Author Author{get;set;}
public IEnumerable<Comment> Comments{get;set;}
}
这是好方法还是我应该将所有数据组装在 ViewModel 类中?
I need just a few confirmation that I do some stuff in the right way or I make horrible mistake :)
1) I put my data access layer (MyProject.Domain) in sepparate assembly. There I have entity object "User" that has properties in 1:1 relation with "User" table in my database. I also extend this user from "MembershipUser" because I use custom schema for membership. Is this good location to store MembershipUser entity?
2) I have "Image" table in database and "Image" entity in my domain library. Image in database has "AuthorId" column which is FK to "User" table. Also image contain list of "comments". So I structure Image domain object like this:
public class Domain
{
public int ImageId{get;set;}
public string Name{get;set;}
public Author Author{get;set;}
public IEnumerable<Comment> Comments{get;set;}
}
Is this good way or maybe I should assemble all data in a ViewModel class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确实应该区分域模型和视图模型。域模型是代表域业务实体的类。它可以是 EF 自动生成的类或其他类。因此,即使是聚合类,它们仍然是域模型,因为它们聚合域实体并且可以与其他域模型一起存储。
视图模型是专门为给定视图定义的类。视图模型始终在 ASP.NET MVC 项目内部定义,因为它们与本身在 ASP.NET MVC 项目中定义的特定视图紧密耦合。域模型可以在单独的程序集中定义。它们也可以在其他应用程序中重复使用。将您的领域模型视为您业务的核心。如果明天 ASP.NET MVC 不再现代,并且出现其他东西,您仍然应该能够重用您的域模型。视图模型只是某些给定和特定视图的域模型的特定表示。
You should really make a distinction between domain models and view models. Domain models are those classes that represent your domain business entities. It could be EF autogenerated classes or whatever. So even being aggregate classes they are still domain models as they aggregate domain entities and could be stored alongside with other domain models.
View models are classes that are specifically defined for a given view. The view models are always defined inside the ASP.NET MVC project because they are tightly coupled to specific views which are themselves defined in the ASP.NET MVC project. Domain models could be defined in separate assembly. They are intended to be resused in other applications as well. Think of your domain models as the core of your business. If tomorrow ASP.NET MVC is no longer modern, and something else comes out you should still be able to reuse your domain models. The view models are only a specific representation of your domain models for some given and specific view.