利用SQL直接生成模型实体类
在网上找来一个别人写好的,生成实体类的SQL代码
declare @TableName sysname = 'lkxxb'
declare @Result varchar(max) = 'public class ' + @TableName + '
{' select @Result = @Result + '
public ' + ColumnType + NullableSign + ' ' + ColumnName + ' { get; set; }
'
from
(
select
replace(col.name, ' ', '_') ColumnName,
column_id ColumnId,
case typ.name
when 'bigint' then 'long'
when 'binary' then 'byte[]'
when 'bit' then 'bool'
when 'char' then 'string'
when 'date' then 'DateTime'
when 'datetime' then 'DateTime'
when 'datetime2' then 'DateTime'
when 'datetimeoffset' then 'DateTimeOffset'
when 'decimal' then 'decimal'
when 'float' then 'float'
when 'image' then 'byte[]'
when 'int' then 'int'
when 'money' then 'decimal'
when 'nchar' then 'char'
when 'ntext' then 'string'
when 'numeric' then 'decimal'
when 'nvarchar' then 'string'
when 'real' then 'double'
when 'smalldatetime' then 'DateTime'
when 'smallint' then 'short'
when 'smallmoney' then 'decimal'
when 'text' then 'string'
when 'time' then 'TimeSpan'
when 'timestamp' then 'DateTime'
when 'tinyint' then 'byte'
when 'uniqueidentifier' then 'Guid'
when 'varbinary' then 'byte[]'
when 'varchar' then 'string'
else 'UNKNOWN_' + typ.name
end ColumnType,
case
when col.is_nullable = 1 and typ.name in ('bigint', 'bit', 'date', 'datetime', 'datetime2', 'datetimeoffset', 'decimal', 'float', 'int', 'money', 'numeric', 'real', 'smalldatetime', 'smallint', 'smallmoney', 'time', 'tinyint', 'uniqueidentifier')
then '?'
else ''
end NullableSign
from sys.columns col
join sys.types typ on
col.system_type_id = typ.system_type_id AND col.user_type_id = typ.user_type_id
where object_id = object_id(@TableName)
) t
order by ColumnId set @Result = @Result + '
}' print @Result
出处:https://www.cnblogs.com/meowv/p/11379829.html
=========================================
后续优化:增加注释说明
利用SQL直接生成模型实体类的更多相关文章
- 在线数据库表(sql语句)生成java实体类工具
相信每个做java开发的读者,都接触过SQL建表语句,尤其是在项目开发初期,因为数据库是项目的基石. 在现代项目开发中,出现了许多ORM框架,通过简单的实体映射,即可实现与数据库的交互,然而我们最初设 ...
- MyEclipse 利用反向功能生成Java 实体类
1.Window -> Open Perspective -> MyEclipse Database Explorer 到DB Broswer界面 2.右键 -> New,新建一个数 ...
- SQL自动生成java实体类POJO
前言 当我们设计完成数据库之后,通常需要创建对应的实体类,有的称为Entity,有的称为DO,都是一个意思,而自己一个个去写非常的麻烦,所以麻烦的时候就需要相应的自动工具类解决这样的麻烦.超级方便~ ...
- 利用SQL生成模型实体类
DECLARE @TableName sysname = 'TableName'; DECLARE @Result VARCHAR(MAX) = 'public class ' + @TableNam ...
- CodeSmith生成SQL Server视图的实体类脚本/对应的生成模板
C#生成sql视图的实体类 using System;using System.Text;using CodeSmith.Engine;using SchemaExplorer;using Syste ...
- 解析利用wsdl.exe生成webservice代理类的详解
利用wsdl.exe生成webservice代理类:根据提供的wsdl生成webservice代理类1.开始->程序->Visual Studio 2005 命令提示2.输入如下红色标记部 ...
- eclipse从数据库逆向生成Hibernate实体类
做项目必然要先进行数据库表设计,然后根据数据库设计建立实体类(VO),这是理所当然的,但是到公司里做项目后,让我认识到,没有说既进行完数据库设计后还要再“自己”建立一变VO.意思是,在项目设计时,要么 ...
- [转]T4模版引擎之生成数据库实体类
本文转自:http://www.cnblogs.com/lzrabbit/archive/2012/07/18/2597953.html 在通过T4模版引擎之基础入门 对T4有了初步印象后,我们开始实 ...
- 修改tt模板让ADO.NET C# POCO Entity Generator With WCF Support 生成的实体类继承自定义基类
折腾几天记载一下,由于项目实际需要,从edmx生成的实体类能自动继承自定义的基类,这个基类不是从edmx文件中添加的Entityobject. 利用ADO.NET C# POCO Entity Gen ...
随机推荐
- SignalR 填坑记
1.发送文字消息没有问题,如何发送文件消息 SignalR可以将参数序列化和反序列化. 这些参数被序列化的格式叫做Hub 协议, 所以Hub协议就是一种用来序列化和反序列化的格式. Hub协议的默认协 ...
- mysql 导入txt数据到数据表【原创】
1.如何将数据表导入到mysql的表中,可以使用:load data infile ... into table ... 示例: load data infile 'e:\datainfo.txt' ...
- 【转帖】HBase读写的几种方式(二)spark篇
HBase读写的几种方式(二)spark篇 https://www.cnblogs.com/swordfall/p/10517177.html 分类: HBase undefined 1. HBase ...
- VMware版本为15安装win7旗舰版不能成功安装VMware tools
VMware版本为15安装win7旗舰版不能成功安装VMware tools 出现的问题: 一直报错说需要系统更新到SP1系统,到网上找了很多升级方式,都未果 直接通过Windows Update,未 ...
- Oracle数据库Schema的简介
百度文库中 Schema 的解释: 数据库中的Schema,为数据库对象的集合,一个用户一般对应一个schema. 官方定义如下: A schema is a collection of databa ...
- IOWebSocketChannel.connect handle errors
https://github.com/dart-lang/web_socket_channel/issues/38 yes, my workaround is to create a WebSocke ...
- Django:RestFramework之-------渲染器
12.渲染器 from rest_framework.renderers import JSONRenderer,BrowsableAPIRenderer,AdminRenderer class Te ...
- mysql DML 数据插入,删除,更新,回退
mysql插入,删除,更新地址:https://wenku.baidu.com/view/194645eef121dd36a32d82b1.html http://www.cnblogs.com/st ...
- Alpha_4
一. 站立式会议照片 二. 工作进展 (1) 昨天已完成的工作 a. 我的·主界面设计 b. 番茄钟的页面及音乐选择弹窗页面设计 c. 实现自定义习惯和设置新习惯的功能页面,并可预览 d.已实现番茄钟 ...
- Jupyter Notebook修改默认的工作目录
Jupyter Notebook修改默认的工作目录 方法1:通过配置文件修改 只适合从命令行启动notebook生成配置文件,如果你已经在windows环境变量中设置好了jupyter noteboo ...