如何自动创建使用PetaPoco库数据库模型? [英] How to automatically create model from database using PetaPoco library?

查看:1128
本文介绍了如何自动创建使用PetaPoco库数据库模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的数据库中的表,我想创建一个getter和setter模型类。对于大多数的任务在我的项目,我使用PetaPoco。我手动创建的模型,但很少表有很多列。

I have a table in my database for which I want to create a model class with getters and setters. For most of the tasks in my project, I am using PetaPoco. I created models manually, but few tables have lots of columns.

有什么办法来创建一个数据库使用PetaPoco模型?

Is there any way to create a model from a database using PetaPoco?

推荐答案

PetaPoco有T4的Visual Studio模板,应该为你做这个。如果你不想让他们全部产生,只是使用的模板,然后从您要生成的* ​​cs文件复制这些类。

PetaPoco has T4 Visual Studio templates that should do this for you. If you don't want to have them all generated, just use the template and then copy those classes from the resulting *.cs file that you want.

您会发现 PetaPoco的GitHub的code回购模板

添加模板到您的项目可以通过两种方式来完成:

Adding templates to your project can be done in two ways:

  1. 在手动复制文件
  2. 在使用的NuGet包中的控制台或使用Visual Studio程序包管理器。上的NuGet网站详细

我会推荐第二个选项,因为你可以建立之前设置你的包自动下载时,没有present(你的CVS的一部分)。

I would recommend the second option, because you can set your packages to auto download before build when not present (part of your CVS).

这篇关于如何自动创建使用PetaPoco库数据库模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆