【笔记】记录NHibernate在.net中的使用

最近在做一个AngularJs的管理平台,后台使用的是.Net Framework 4.5,搭配了NHibernate + Redis + Elasticsearch + Mysql等技术;

在新增接口的时候发现有些地方需要映射实体类等;

 

于是从官网找了对NHibernate配置映射文件时的类型进行归档,以供学习参考

 

值类型

 

 

NHibernate类型

.Net类型

数据库类型

备注

AnsiChar

System.Char

DbType.AnsiStringFixedLength - 1 char

必须指定type =“AnsiChar”。

Boolean

System.Boolean

DbType.Boolean

未指定类型属性时为默认值

Byte

System.Byte

DbType.Byte

未指定类型属性时为默认值

Char

System.Char

DbType.StringFixedLength - 1 char

未指定类型属性时为默认值

Currency

System.Decimal

DbType.Currency

必须指定type =“Currency”。

Date

System.DateTime

DbType.Date

必须指定type=“Date”

DateTime

System.DateTime

DbType.DateTime / DbType.DateTime2(1)

未指定类型属性时的默认值。从NHibernate v5.0开始不再忽略小数秒。

DateTimeNoMs

System.DateTime

DbType.DateTime / DbType.DateTime2(1)

必须指定type =“DateTimeNoMs”。忽略小数秒。自NHibernate v5.0起可用。

DateTime2

System.DateTime

DbType.DateTime2

必须指定type =“DateTime2”。自NHibernate v5.0以来已过时,请改用DateTime。

DateTimeOffset

System.DateTimeOffset

DbType.DateTimeOffset

未指定类型属性时的默认值。

DbTimestamp

System.DateTime

DbType.DateTime / DbType.DateTime2(1)

必须指定type =“DbTimestamp”。当用作 版本字段时,使用数据库在专用查询中检索的当前时间,而不是客户端的当前时间。如果缺少数据库支持,它将回退到客户端的当前时间。

Decimal

System.Decimal

DbType.Decimal

未指定类型属性时的默认值。

Double

System.Double

DbType.Double

未指定类型属性时的默认值。

Guid

System.Guid

DbType.Guid

未指定类型属性时的默认值。

Int16

System.Int16

DbType.Int16

未指定类型属性时的默认值。

Int32

System.Int32

DbType.Int32

未指定类型属性时的默认值。

Int64

System.Int64

DbType.Int64

未指定类型属性时的默认值。

LocalDateTime

System.DateTime

DbType.DateTime / DbType.DateTime2(1)

必须指定type =“LocalDateTime”。确保 DateTimeKind设置为DateTimeKind.Local。如果设置了另一种日期,则抛出。从NHibernate v5.0开始不再忽略小数秒。

LocalDateTimeNoMs

System.DateTime

DbType.DateTime / DbType.DateTime2(1)

必须指定type =“LocalDateTimeNoMs”。与LocalDateTime类似, 但忽略小数秒。自NHibernate v5.0起可用。

PersistentEnum

A System.Enum

The DbType for the underlying value.

不要在映射中指定type =“PersistentEnum”。而是指定枚举的程序集限定名称或让NHibernate使用Reflection来“猜测”类型。Enum的UnderlyingType用于确定正确的DbType。

SByte

System.SByte

DbType.SByte

未指定类型属性时的默认值。

Single

System.Single

DbType.Single

未指定类型属性时的默认值。

Ticks

System.DateTime

DbType.Int64

必须指定type =“Ticks”。这是与UtcTicks一起“添加时间戳”列的推荐方法。

Time

System.DateTime

DbType.Time

必须指定type =“Time”。

TimeAsTimeSpan

System.TimeSpan

DbType.Time

必须指定type =“TimeAsTimeSpan”。

TimeSpan

System.TimeSpan

DbType.Int64

未指定类型属性时的默认值。

Timestamp

System.DateTime

DbType.DateTime / DbType.DateTime2(1)

未指定类型属性时的默认值。

TrueFalse

System.Boolean

DbType.AnsiStringFixedLength - 1 char either ‘T’ or ‘F’

type=“TrueFalse” must be specified.

UInt16

System.UInt16

DbType.UInt16

未指定类型属性时的默认值。

UInt32

System.UInt32

DbType.UInt32

未指定类型属性时的默认值。

UInt64

System.UInt64

DbType.UInt64

未指定类型属性时的默认值。

UtcDateTime

System.DateTime

DbType.DateTime / DbType.DateTime2(1)

确保DateTimeKind设置为DateTimeKind.Utc。如果设置了另一种日期,则抛出。从NHibernate v5.0开始不再忽略小数秒。

UtcDateTimeNoMs

System.DateTime

DbType.DateTime / DbType.DateTime2(1)

必须指定type =“UtcDateTimeNoMs”。与UtcDateTime类似, 但忽略小数秒。自NHibernate v5.0起可用。

UtcDbTimestamp

System.DateTime

DbType.DateTime / DbType.DateTime2(1)

必须指定type =“UtcDbTimestamp”。当用作 版本字段时,使用数据库在专用查询中检索的当前UTC时间,而不是客户端的当前时间。如果缺少数据库支持,它将回退到客户端的当前时间。

UtcTicks

System.DateTime

DbType.Int64

必须指定type =“UtcTicks”。这是与Ticks一起“加时间”列的建议方法。确保DateTimeKind设置为DateTimeKind.Utc。如果设置了另一种日期,则抛出。

YesNo

System.Boolean

DbType.AnsiStringFixedLength - 1 char either ‘Y’ or ‘N’

必须指定type =“YesNo”。

 

 

映射对象类型

 

NHibernate类型

.Net类型

数据库类型

备注

AnsiString

System.String

DbType.AnsiString

必须指定type =“AnsiString”。

CultureInfo

System.Globalization.CultureInfo

DbType.String - 5 chars for culture

未指定类型属性时的默认值。

Binary

System.Byte[]

DbType.Binary

未指定类型属性时的默认值。

Type

System.Type

DbType.String holding Assembly Qualified Name.

未指定类型属性时的默认值。

String

System.String

DbType.String

未指定类型属性时的默认值。

Uri

System.Uri

DbType.String

未指定类型属性时的默认值。

 

大数据类型

 

NHibernate类型

.Net类型

数据库类型

备注

StringClob

System.String

DbType.String

必须指定type =“StringClob”。整个字段被读入内存。

BinaryBlob

System.Byte[]

DbType.Binary

必须指定type =“BinaryBlob”。整个字段被读入内存。

Serializable

Any System.Object that is marked with SerializableAttribute.

DbType.Binary

应指定type =“Serializable”。如果没有为Property找到NHibernate Type,则这是后备类型。

XDoc

System.Xml.Linq.XDocument

DbType.Xml

未指定类型属性时的默认值。整个字段被读入内存。

XmlDoc

System.Xml.XmlDocument

DbType.Xml

未指定类型属性时的默认值。整个字段被读入内存。

 

 

参考官网文档:https://nhibernate.info/doc/nhibernate-reference/mapping.html#mapping-types

posted @   浪潮行舟  阅读(58)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示