创建索引
分表的用户注意了:请升级到5.0.8.6-preview03修复了分表问题
//普通索引 [SugarIndex("index_codetable1_name",nameof(CodeFirstTable1.Name),OrderByType.Asc)] //唯一索引 (true表示唯一索引 或者叫 唯一约束) [SugarIndex("unique_codetable1_CreateTime", nameof(CodeFirstTable1.CreateTime), OrderByType.Desc,true)] //复合普通索引 [SugarIndex("index_codetable1_nameid", nameof(CodeFirstTable1.Name), OrderByType.Asc, nameof(CodeFirstTable1.Id), OrderByType.Desc)] public class CodeFirstTable1 { [SugarColumn(IsIdentity = true, IsPrimaryKey = true)] public int Id { get; set; } public string Name { get; set; } [SugarColumn(ColumnDataType = "Nvarchar(255)")]//custom public string Text { get; set; } [SugarColumn(IsNullable = true)] public DateTime CreateTime { get; set; } } //分表的用户注意了:请升级到5.0.8.6-preview03修复了分表问题 |
给索引名添加占位符
//占位符 {table} {db}//请升级到 5.0.2.3preivew04//使用 {db} 进行占位符替换,小写不要有空格[SugarIndex("{db}index_codetable1_name",nameof(CodeFirstTable1.Name),OrderByType.Asc)]//表名占位符(自动分表不需要加这个自动的)[SugarIndex("index_{table}_name",nameof(CodeFirstTable1.Name),OrderByType.Asc)] |
索引include 5.1.3.31-preview11
//不要有空格并且小写等于 include(name,id) [SugarIndex("IndexUnituadfasf1_longx{include:name,id}", nameof(longx), OrderByType.Asc)] public class Unituadfasf1 { public ulong longx { get; set; } public int id { get; set; } public string name { get; set; } } |