mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-09 09:50:54 +08:00
update
28
实体特性.md
28
实体特性.md
@@ -1,5 +1,5 @@
|
||||
|
||||
# 主键(Primary Key)
|
||||
## 主键(Primary Key)
|
||||
|
||||
```csharp
|
||||
class Topic {
|
||||
@@ -14,7 +14,7 @@ class Topic {
|
||||
|
||||
* 当主键是 Guid 类型时,插入时会自动创建(有序、不重复)的值,所以不需要自己赋值;(支持分布式)
|
||||
|
||||
# 自增(Identity)
|
||||
## 自增(Identity)
|
||||
|
||||
```csharp
|
||||
class Topic {
|
||||
@@ -27,7 +27,7 @@ class Topic {
|
||||
|
||||
* 当没有指明主键时,标记自增的成员将成为主键;
|
||||
|
||||
# 唯一键(Unique Key)
|
||||
## 唯一键(Unique Key)
|
||||
|
||||
```csharp
|
||||
class AddUniquesInfo {
|
||||
@@ -49,7 +49,7 @@ class AddUniquesInfo {
|
||||
|
||||
唯一键,在多个属性指定相同的标识,代表联合键;可使用逗号分割多个 UniqueKey 名。
|
||||
|
||||
# 数据库类型(DbType)
|
||||
## 数据库类型(DbType)
|
||||
|
||||
```csharp
|
||||
class Topic {
|
||||
@@ -71,7 +71,7 @@ class Topic {
|
||||
|
||||
MaxLengthAttribute 可以在任意地方定义,因为内部采用反射查找方法。该特性通常定义在 System.ComponentModel.DataAnnotations.MaxLengthAttribute,但如果找不到该类,可自行在项目中定义名称为 MaxLengthAttribute 的特性类,和它的属性 public int Length。
|
||||
|
||||
# 可空(Nullable)
|
||||
## 可空(Nullable)
|
||||
|
||||
```csharp
|
||||
class Topic {
|
||||
@@ -87,7 +87,7 @@ class Topic {
|
||||
|
||||
一般在使用 string 类型时,才需要手工指明是否可空(string 默认可空);
|
||||
|
||||
# 忽略(Ignore)
|
||||
## 忽略(Ignore)
|
||||
|
||||
```csharp
|
||||
class Topic {
|
||||
@@ -107,7 +107,7 @@ class Topic {
|
||||
}
|
||||
```
|
||||
|
||||
# 乐观锁(RowVersion)
|
||||
## 乐观锁(RowVersion)
|
||||
|
||||
```csharp
|
||||
class Topic {
|
||||
@@ -127,7 +127,7 @@ class Topic {
|
||||
|
||||
> 适用 SetSource 更新,无论使用什么方法更新 version 的值都会增加 1
|
||||
|
||||
# 自定义类型映射(MapType)
|
||||
## 自定义类型映射(MapType)
|
||||
|
||||
```csharp
|
||||
class EnumTestMap {
|
||||
@@ -155,13 +155,13 @@ public enum ToStringMapEnum { 中国人, abc, 香港 }
|
||||
|
||||
BigInteger 都可以映射使用了,但请注意:仅仅是 CURD 方便, Equals == 判断可以使用,无法实现 + - * / 等操作;
|
||||
|
||||
# 字段位置(Position)
|
||||
## 字段位置(Position)
|
||||
|
||||
适用场景:当实体类继承时,CodeFirst创建表的字段顺序可能不是想要的,通过该特性可以设置顺序。
|
||||
|
||||
创建表时指定字段位置,如:[Column(Position = 1],可为负数即反方向位置;
|
||||
|
||||
# 名称
|
||||
## 名称
|
||||
|
||||
FreeSql 默认使用实体的类名,或属性名与数据库映射,也可以指定映射的名称;
|
||||
|
||||
@@ -184,7 +184,7 @@ class Topic2 {
|
||||
|
||||
> 实体的属性也有相同的功能,[Column(Name = "xxx")]
|
||||
|
||||
# 禁用迁移
|
||||
## 禁用迁移
|
||||
|
||||
IFreeSql.CodeFirst.IsAutoSyncStructure 可设置全局【自动迁移结构】功能,也可通过 FreeSqlBuilder.UseAutoSyncStructure(true) 创建 IFreeSql 的时候设置功能。
|
||||
|
||||
@@ -198,7 +198,7 @@ class ModelDisableSyncStructure {
|
||||
}
|
||||
```
|
||||
|
||||
# 备注
|
||||
## 备注
|
||||
|
||||
FreeSql CodeFirst 支持将 c# 代码内的注释,迁移至数据库的备注。先决条件:
|
||||
|
||||
@@ -206,11 +206,11 @@ FreeSql CodeFirst 支持将 c# 代码内的注释,迁移至数据库的备注
|
||||
|
||||
2、xml 文件必须与程序集同目录,且文件名:xxx.dll -> xxx.xml;
|
||||
|
||||
# 优先级
|
||||
## 优先级
|
||||
|
||||
数据库特性 > 实体特性 > FluantApi(配置特性) > Aop(配置特性)
|
||||
|
||||
# 参考资料
|
||||
## 参考资料
|
||||
|
||||
- [《FluentApi,享受纯净实体类》](https://github.com/2881099/FreeSql/wiki/FluentApi)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user