using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace OrmTest { public partial class NewUnitTest { public static void Save() { Db.CodeFirst.InitTables(); Db.DbMaintenance.TruncateTable(); Db.Saveable(new UnitSysMenu() { ID="aa", ButtonList="", CreateName="a", CreateTime=DateTime.Now, ImageUrl="", IsDel=true, MenuCode="a", NavigateUrl="a", UpdateName="", Remark="", UpdateTime=DateTime.Now }).ExecuteReturnEntity(); var db = Db; db.CodeFirst.InitTables(); db.DbMaintenance.TruncateTable(); List list2 = new List(); list2.Add(new UinitBlukTable() { Id = 1, Name = "a", Create = DateTime.Now }); list2.Add(new UinitBlukTable() { Id = 2, Name = "a", Create = DateTime.Now }); list2.Add(new UinitBlukTable() { Id = 0, Name = "a", Create = DateTime.Now }); db.Insertable(list2[0]).ExecuteCommand(); var x = Db.Storageable(list2) .Saveable() .ToStorage(); x.AsInsertable.ExecuteCommand(); x.AsUpdateable.ExecuteCommand(); db.DbMaintenance.TruncateTable(); } } internal class UinitBlukTable { public UinitBlukTable() { } [SugarColumn(IsPrimaryKey =true)] public int Id { get; set; } public string Name { get; set; } public DateTime Create { get; set; } } public class BaseEntity { /// /// ID /// [SugarColumn(IsPrimaryKey = true, ColumnDescription = "ID", Length = 32)] public string ID { get; set; } /// /// 删除标记 /// [ SugarColumn(ColumnDescription = "删除标记")] public bool IsDel { get; set; } /// /// 排序字段 /// [SugarColumn(ColumnDescription = "排序字段", IsIdentity = true)] public int SortIndex { get; set; } /// /// 添加操作员 /// [ SugarColumn(ColumnDescription = "添加操作员", Length = 10, IsNullable = true)] public string CreateName { get; set; } /// /// 添加时间 /// [ SugarColumn(ColumnDescription = "添加时间", IsNullable = true)] public DateTime? CreateTime { get; set; } /// /// 修改操作员 /// [ SugarColumn(ColumnDescription = "修改操作员", Length = 10, IsNullable = true)] public string UpdateName { get; set; } /// /// 修改时间 /// [ SugarColumn(ColumnDescription = "修改时间", IsNullable = true)] public DateTime? UpdateTime { get; set; } /// /// 备注 /// [SugarColumn(ColumnDescription = "备注", Length = 150, IsNullable = true)] public string Remark { get; set; } } public class UnitSysMenu : BaseEntity { public UnitSysMenu() { } /// /// 菜单图标 /// [SqlSugar.SugarColumn(Length = 150, ColumnDescription = "菜单图标")] public string ImageUrl { get; set; } /// /// 菜单编码 /// [SqlSugar.SugarColumn(Length = 50, ColumnDescription = "菜单编码")] public string MenuCode { get; set; } /// /// 菜单地址 /// [ SqlSugar.SugarColumn(Length = 200, IsNullable = true, ColumnDescription = "菜单地址")] public string NavigateUrl { get; set; } /// /// 菜单功能 /// [SqlSugar.SugarColumn(IsIgnore = true)] public string ButtonList { get; set; } /// /// 排序字段 /// [SugarColumn(ColumnDescription = "排序字段", IsIdentity = true)] public int SortIndex { get; set; } } }