代码生成 - 通过引用数据库表生成 DTO。

发布于 2024-12-11 19:07:29 字数 116 浏览 1 评论 0原文

我正在使用 NHibernate。我需要生成 DTO 来携带数据。我不想用手做。因此,我正在寻找捷径和工具来帮助我。我希望找到一个简单的工具来生成镜像数据库表的对象。这些对象的属性将具有与数据库表相同的名称和等效类型。

I'm working with NHibernate. I need to generate DTOs to carry data around. I don't want to do it by hand. Hence I'm looking for shortcuts and tools to help me. I was hoping to find a simple tool that generates a objects which mirror the database tables. The properties of these objects would have same name and equivalent types as of database tables.

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

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

发布评论

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

评论(3

故事还在继续 2024-12-18 19:07:29

查看数据库并创建类型的工具称为 ORM(对象关系映射器)。有免费的和商业的:Entity Framework 和 LLBLGEN 浮现在脑海中。

如果您已经有了自己的类型,则可以使用 AutoMapper 转换为 DTO:

AutoMapper 是一个对象-对象映射器。对象-对象映射的工作原理
将一种类型的输入对象转换为一种类型的输出对象
不同类型。 AutoMapper 的有趣之处在于它提供了
一些有趣的约定可以消除计算中的肮脏工作
知道如何将类型 A 映射到类型 B。只要类型 B 遵循
AutoMapper的既定约定,几乎是零配置
需要映射两种类型。

A tool that looks at your database and creates types is called an ORM (Object Relational Mapper). There are both free and commercial ones available: Entity Framework and LLBLGEN spring to mind.

If you already have your types, you could use AutoMapper to convert to DTOs:

AutoMapper is an object-object mapper. Object-object mapping works by
transforming an input object of one type into an output object of a
different type. What makes AutoMapper interesting is that it provides
some interesting conventions to take the dirty work out of figuring
out how to map type A to type B. As long as type B follows
AutoMapper's established convention, almost zero configuration is
needed to map two types.

老娘不死你永远是小三 2024-12-18 19:07:29

Visual Nhibernate 可以从数据库架构生成域对象。然后您可以修改这些对象并最终得到您需要的 DTO。一旦您拥有这两种对象类型,您就可以遵循 Mitch 的建议并使用 EmitMapper 或 AutoMapper 等工具自动将 Domain 对象映射到 DTOS。

Visual Nhibernate can generate domain objects from your database schema. You could then modify these objects and end up with the DTOs you need. Once you have both object types you can follow Mitch's advice and use a tool like EmitMapper or AutoMapper to automatically map Domain objects to DTOS.

困倦 2024-12-18 19:07:29

在观看 http://summerofnhibernate.com/ 的一场会议时找到了我正在寻找的内容,特别是会议 08:有效数据库驱动建模技术。

他使用的工具名为 MyGeneration,它通过查看数据库表来构建 DTO。

Found what I was looking for while watching one of the sessions of http://summerofnhibernate.com/ specifically Session 08: Effective Techniques for Database-Driven Modeling.

The tool he is using is called MyGeneration which builds DTOs by looking at database tables.

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