T4 用于通过 LLBLGen Pro 实体生成 POCO?
据我了解,LLBLGen Pro 无法在其自己的实体上生成 POCO(请参见此处:http://www .llblgen.com/Pages/featuresLLBLGenPro.aspx)。
有没有人编写过 T4,它将生成与 LLBLGen Pro 实体相对应的 POCO 类,并生成适当的转换逻辑以往返于实体和 POCO?还有其他人提出了一种不涉及手动编写大量转换代码的解决方案吗?
As I understand it, LLBLGen Pro cannot generate POCOs over it's own entities (see here: http://www.llblgen.com/Pages/featuresLLBLGenPro.aspx).
Has anyone written a T4 that will generate POCO classes corresponding to LLBLGen Pro entities and generate the appropriate transformation logic to go to and from an entity and POCO? Has anyone else come up with a solution that doesn't involve manually writing tons of transformation code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们从 LLBLGen 生成 DTO,而不是使用 T4。
我们需要从实体创建 DTO。从技术上讲,这些不是 POCO,因为它们具有 ToEntity() 和 FromEntity() 方法,但也许这对您有用。
我们创建了一个
IDTO
接口,然后由 DTO 类(每个实体一个)实现该接口。我们没有修改实体模板,而是添加了将实体转换为 DTO(以及许多其他帮助器转换)的DTOExtension
方法。以下是您可以在 LLBLGen v2.6 中使用的模板文件。版本 3 中的模板设计器更易于使用,如果需要,您可以将大部分代码转换为版本 3。
文件:entityDTOInterface.template
文件:entityDTO.template
文件:dtoExtensions.template
文件:DTO.tasks
最后,将以下内容添加到 *.preset 文件中的适当位置。这将在您的生成预设中定义上面的代码生成任务。
We generated DTOs from LLBLGen rather than using T4.
We had a need to create DTOs from an Entity. These aren't technically POCOs because they have a
ToEntity()
andFromEntity()
method, but perhaps this will work for you.We created an
IDTO<T>
interface that was then implemented by the DTO classes (one for each entity). Rather than modifying the entity templates, we addedDTOExtension
methods that would convert an Entity to a DTO (as well as numerous other helper conversions).Here are the template files you can use within LLBLGen v2.6. The template designer in version 3 is much easier to use, and you can convert much of this code for version 3 if you need to.
File: entityDTOInterface.template
File: entityDTO.template
File: dtoExtensions.template
FILE: DTO.tasks
Finally, add the following to the appropriate place in your *.preset file. This will define the code generation task above within your generation preset.