├── .gitattributes ├── .gitignore ├── NewTest ├── Dao │ └── SugarDao.cs ├── DataBase │ └── demo.sqlite ├── Demos │ ├── Ado.cs │ ├── AttributesMapping.cs │ ├── CreateClass.cs │ ├── Delete.cs │ ├── EnumDemo.cs │ ├── Filter.cs │ ├── Filter2.cs │ ├── IDemos.cs │ ├── IgnoreErrorColumns.cs │ ├── InitConfig.cs │ ├── Insert.cs │ ├── Log.cs │ ├── MappingColumns.cs │ ├── MappingTable.cs │ ├── PubMethod.cs │ ├── Select.cs │ ├── SerialNumber.cs │ ├── SerializerDateFormat.cs │ ├── Test.cs │ ├── Tran.cs │ └── Update.cs ├── Models │ ├── Area.cs │ ├── InsertTest.cs │ ├── LanguageTest.cs │ ├── School.cs │ ├── Student.cs │ ├── Student2.cs │ ├── StudentGroup.cs │ ├── Subject.cs │ ├── Test.cs │ ├── TestUpdateColumns.cs │ ├── V_LanguageTest.cs │ └── V_Student.cs ├── NewTest.csproj ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── app.config ├── x64 │ └── SQLite.Interop.dll └── x86 │ └── SQLite.Interop.dll ├── README.md ├── SqlSugar.sln.lnk ├── SqlSugar ├── Base │ └── SqlHelper.cs ├── Cloud │ ├── CloudModels.cs │ ├── CloudPubMethod.cs │ └── TaskExtensions.cs ├── Core │ ├── IDataReaderEntityBuilder.cs │ ├── IDataRecordExtensions.cs │ └── ResolveExpress │ │ ├── Constant.cs │ │ ├── Expressions.cs │ │ ├── Main.cs │ │ ├── Method.cs │ │ ├── Models.cs │ │ ├── Property.cs │ │ ├── ResolveFieldName.cs │ │ └── ResolveSelect.cs ├── Generating │ ├── ClassGenerating.cs │ ├── ClassTemplate.cs │ └── SugarAttribute.cs ├── Lib │ ├── System.Data.SQLite.dll │ └── System.Data.SQLite.xml ├── NuGet.exe ├── Properties │ └── AssemblyInfo.cs ├── PubModel │ ├── KeyValue.cs │ ├── PubEnum.cs │ └── PubModel.cs ├── Queryable │ ├── Queryable.cs │ └── QueryableExtensions.cs ├── SqlSugarClient.cs ├── Sqlable │ ├── Sqlable.cs │ └── SqlableExtensions.cs ├── SqliteSugar.csproj ├── SqliteSugar.nuspec ├── Tool │ ├── CacheManager.cs │ ├── Check.cs │ ├── FileSugar.cs │ ├── IEnumerableExtensions.cs │ ├── IStorageObject.cs │ ├── IsWhatExtensions.cs │ ├── JsonConverter.cs │ ├── LanguageHelper.cs │ ├── PubConvert.cs │ ├── SqlException.cs │ ├── SqlSugarTool.cs │ ├── SqlSugarToolCoreDiff.cs │ ├── SqlSugarToolExtensions.cs │ └── SqlSugarToolWithSqlMethod.cs └── bat.bat └── SqliteSugar.sln /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | build/ 19 | bld/ 20 | [Bb]in/ 21 | [Oo]bj/ 22 | 23 | # Visual Studio 2015 cache/options directory 24 | .vs/ 25 | 26 | # MSTest test Results 27 | [Tt]est[Rr]esult*/ 28 | [Bb]uild[Ll]og.* 29 | 30 | # NUNIT 31 | *.VisualState.xml 32 | TestResult.xml 33 | 34 | # Build Results of an ATL Project 35 | [Dd]ebugPS/ 36 | [Rr]eleasePS/ 37 | dlldata.c 38 | 39 | # DNX 40 | project.lock.json 41 | artifacts/ 42 | 43 | *_i.c 44 | *_p.c 45 | *_i.h 46 | *.ilk 47 | *.meta 48 | *.obj 49 | *.pch 50 | *.pdb 51 | *.pgc 52 | *.pgd 53 | *.rsp 54 | *.sbr 55 | *.tlb 56 | *.tli 57 | *.tlh 58 | *.tmp 59 | *.tmp_proj 60 | *.log 61 | *.vspscc 62 | *.vssscc 63 | .builds 64 | *.pidb 65 | *.svclog 66 | *.scc 67 | 68 | # Chutzpah Test files 69 | _Chutzpah* 70 | 71 | # Visual C++ cache files 72 | ipch/ 73 | *.aps 74 | *.ncb 75 | *.opensdf 76 | *.sdf 77 | *.cachefile 78 | 79 | # Visual Studio profiler 80 | *.psess 81 | *.vsp 82 | *.vspx 83 | 84 | # TFS 2012 Local Workspace 85 | $tf/ 86 | 87 | # Guidance Automation Toolkit 88 | *.gpState 89 | 90 | # ReSharper is a .NET coding add-in 91 | _ReSharper*/ 92 | *.[Rr]e[Ss]harper 93 | *.DotSettings.user 94 | 95 | # JustCode is a .NET coding add-in 96 | .JustCode 97 | 98 | # TeamCity is a build add-in 99 | _TeamCity* 100 | 101 | # DotCover is a Code Coverage Tool 102 | *.dotCover 103 | 104 | # NCrunch 105 | _NCrunch_* 106 | .*crunch*.local.xml 107 | 108 | # MightyMoose 109 | *.mm.* 110 | AutoTest.Net/ 111 | 112 | # Web workbench (sass) 113 | .sass-cache/ 114 | 115 | # Installshield output folder 116 | [Ee]xpress/ 117 | 118 | # DocProject is a documentation generator add-in 119 | DocProject/buildhelp/ 120 | DocProject/Help/*.HxT 121 | DocProject/Help/*.HxC 122 | DocProject/Help/*.hhc 123 | DocProject/Help/*.hhk 124 | DocProject/Help/*.hhp 125 | DocProject/Help/Html2 126 | DocProject/Help/html 127 | 128 | # Click-Once directory 129 | publish/ 130 | 131 | # Publish Web Output 132 | *.[Pp]ublish.xml 133 | *.azurePubxml 134 | ## TODO: Comment the next line if you want to checkin your 135 | ## web deploy settings but do note that will include unencrypted 136 | ## passwords 137 | #*.pubxml 138 | 139 | *.publishproj 140 | 141 | # NuGet Packages 142 | *.nupkg 143 | # The packages folder can be ignored because of Package Restore 144 | **/packages/* 145 | # except build/, which is used as an MSBuild target. 146 | !**/packages/build/ 147 | # Uncomment if necessary however generally it will be regenerated when needed 148 | #!**/packages/repositories.config 149 | 150 | # Windows Azure Build Output 151 | csx/ 152 | *.build.csdef 153 | 154 | # Windows Store app package directory 155 | AppPackages/ 156 | 157 | # Visual Studio cache files 158 | # files ending in .cache can be ignored 159 | *.[Cc]ache 160 | # but keep track of directories ending in .cache 161 | !*.[Cc]ache/ 162 | 163 | # Others 164 | ClientBin/ 165 | [Ss]tyle[Cc]op.* 166 | ~$* 167 | *~ 168 | *.dbmdl 169 | *.dbproj.schemaview 170 | *.pfx 171 | *.publishsettings 172 | node_modules/ 173 | orleans.codegen.cs 174 | 175 | # RIA/Silverlight projects 176 | Generated_Code/ 177 | 178 | # Backup & report files from converting an old project file 179 | # to a newer Visual Studio version. Backup files are not needed, 180 | # because we have git ;-) 181 | _UpgradeReport_Files/ 182 | Backup*/ 183 | UpgradeLog*.XML 184 | UpgradeLog*.htm 185 | 186 | # SQL Server files 187 | *.mdf 188 | *.ldf 189 | 190 | # Business Intelligence projects 191 | *.rdl.data 192 | *.bim.layout 193 | *.bim_*.settings 194 | 195 | # Microsoft Fakes 196 | FakesAssemblies/ 197 | 198 | # Node.js Tools for Visual Studio 199 | .ntvs_analysis.dat 200 | 201 | # Visual Studio 6 build log 202 | *.plg 203 | 204 | # Visual Studio 6 workspace options file 205 | *.opt 206 | 207 | # LightSwitch generated files 208 | GeneratedArtifacts/ 209 | _Pvt_Extensions/ 210 | ModelManifest.xml 211 | -------------------------------------------------------------------------------- /NewTest/Dao/SugarDao.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using SQLiteSugar; 5 | namespace NewTest.Dao 6 | { 7 | /// 8 | /// SqlSugar 9 | /// 10 | public class SugarDao 11 | { 12 | //禁止实例化 13 | private SugarDao() 14 | { 15 | 16 | } 17 | public static string ConnectionString 18 | { 19 | get 20 | { 21 | string reval = "DataSource=" + System.AppDomain.CurrentDomain.BaseDirectory + "DataBase\\demo.sqlite"; ; //这里可以动态根据cookies或session实现多库切换 22 | return reval; 23 | } 24 | } 25 | public static SqlSugarClient GetInstance() 26 | { 27 | 28 | var db = new SqlSugarClient(ConnectionString); 29 | db.IsEnableLogEvent = true;//启用日志事件 30 | db.LogEventStarting = (sql, par) => { Console.WriteLine(sql + " " + par+"\r\n"); }; 31 | return db; 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /NewTest/DataBase/demo.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DotNetNext/SqliteSugar/475c16eedeff52864f3d5e78829e5f1b74f6535c/NewTest/DataBase/demo.sqlite -------------------------------------------------------------------------------- /NewTest/Demos/Ado.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NewTest.Dao; 6 | using Models; 7 | using System.Data.SqlClient; 8 | using System.Data.SQLite; 9 | 10 | namespace NewTest.Demos 11 | { 12 | //完美兼容SqlHelper的所有功能 13 | public class Ado:IDemos 14 | { 15 | 16 | public void Init() 17 | { 18 | Console.WriteLine("启动Ado.Init"); 19 | using (var db = SugarDao.GetInstance()) 20 | { 21 | var r1 = db.GetDataTable("select * from student"); 22 | var r2 = db.GetSingle("select * from student LIMIT 0,1"); 23 | var r3 = db.GetScalar("select count(1) from student"); 24 | var r4 = db.GetReader("select count(1) from student"); 25 | r4.Dispose(); 26 | var r5 = db.GetString("select name from student LIMIT 0,1"); 27 | var r6 = db.ExecuteCommand("select 1"); 28 | 29 | 30 | //参数支持 31 | var p1 = db.GetDataTable("select * from student where id=@id", new {id=1 }); 32 | var p2 = db.GetDataTable("select * from student where id=@id", new Dictionary() { { "id", "1" } });//目前只支持 Dictionary和Dictionary 33 | var p3 = db.GetDataTable("select * from student where id=@id", new SQLiteParameter("@id", 1)); 34 | 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /NewTest/Demos/AttributesMapping.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NewTest.Dao; 6 | using Models; 7 | using System.Data.SqlClient; 8 | using SQLiteSugar; 9 | namespace NewTest.Demos 10 | { 11 | //通过属性的方法设置别名表和别名字段(主键和自添列都无需设置 SQLSUGAR会帮你自动处理) 12 | //注意:【属性映射和 (SetMappingTables、SetMappingColumns)方式映射 2种选其中一,不清楚底层缓存机质不建议同时使用】 13 | public class AttributesMapping : IDemos 14 | { 15 | 16 | public void Init() 17 | { 18 | Console.WriteLine("启动AttributesMapping.Init"); 19 | using (var db = DBManager.GetInstance()) 20 | { 21 | 22 | //查询 23 | var list = db.Queryable() 24 | .Where(it => it.className.Contains("小")).OrderBy(it => it.classSchoolId).Select(it => new V_Student() { id = it.classId, name = it.className }).ToList(); 25 | var list2 = db.Queryable() 26 | .JoinTable((s1, s2) => s1.classSchoolId == s2.classId) 27 | .OrderBy((s1, s2) => s1.classId) 28 | .Select((s1, s2) => new V_Student() { id = s1.classId, name = s1.className, SchoolName = s2.className }).ToList(); 29 | 30 | //添加 31 | TestStudent s = new TestStudent(); 32 | s.className = "属性名"; 33 | s.classSchoolId = 1; 34 | var id = db.Insert(s); 35 | s.classId = id.ObjToInt(); 36 | 37 | 38 | db.SqlBulkCopy(new List() { s }); 39 | 40 | 41 | //更新 42 | db.Update(s); 43 | db.Update(s, 100); 44 | db.Update(s, it => it.classId == 100); 45 | db.SqlBulkReplace(new List() { s }); 46 | 47 | //删除 48 | db.Delete(it => it.classId == 100); 49 | 50 | //根据实体赋值实体一定要有主键,并且要有值。 51 | db.Delete(new TestStudent() { classId = 200 }); 52 | } 53 | } 54 | 55 | /// 56 | /// 属性只作为初始化映射,SetMappingTables和SetMappingColumns可以覆盖 57 | /// 58 | [SugarMapping(TableName = "Student")] 59 | public class TestStudent 60 | { 61 | 62 | [SugarMapping(ColumnName = "id")] 63 | public int classId { get; set; } 64 | 65 | [SugarMapping(ColumnName = "name")] 66 | public string className { get; set; } 67 | 68 | [SugarMapping(ColumnName = "sch_id")] 69 | public int classSchoolId { get; set; } 70 | 71 | public int isOk { get; set; } 72 | 73 | /// 74 | /// 数据库并没有这一列 75 | /// 76 | public string errorField { get; set; } 77 | } 78 | 79 | 80 | [SugarMapping(TableName = "School")] 81 | public class TestSchool 82 | { 83 | 84 | [SugarMapping(ColumnName = "id")] 85 | public int classId { get; set; } 86 | 87 | [SugarMapping(ColumnName = "name")] 88 | public string className { get; set; } 89 | 90 | public int AreaId = 1; 91 | } 92 | } 93 | 94 | public class DBManager 95 | { 96 | 97 | public static SqlSugarClient GetInstance() 98 | { 99 | var db = new SqlSugarClient(SugarDao.ConnectionString); 100 | db.IsEnableAttributeMapping = true;//启用属性映射 101 | db.IsIgnoreErrorColumns = true;//忽略非数据库列 102 | 103 | 104 | 105 | db.IsEnableLogEvent = true;//启用日志事件 106 | db.LogEventStarting = (sql, par) => { Console.WriteLine(sql + " " + par + "\r\n"); }; 107 | 108 | 109 | return db; 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /NewTest/Demos/CreateClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NewTest.Dao; 6 | using Models; 7 | using System.Data.SqlClient; 8 | using SQLiteSugar; 9 | 10 | namespace NewTest.Demos 11 | { 12 | //生成实体函数 13 | public class CreateClass : IDemos 14 | { 15 | 16 | public void Init() 17 | { 18 | Console.WriteLine("启动CreateClass.Init"); 19 | using (var db = SugarDao.GetInstance()) 20 | { 21 | //可以结合别名表,请看别名表的用法 22 | //db.SetMappingTables(mappingTableList); 23 | 24 | db.ClassGenerating.CreateClassFiles(db, ("e:/TestSqliteModels"), "Models"); 25 | 26 | 27 | //批量设置别名表,可以方便生成指定格式的实体对象 28 | db.ClassGenerating.ForeachTables(db, tableName => 29 | { 30 | db.AddMappingTable(new KeyValue() { Key = "Rename_"+tableName, Value = tableName }); 31 | }); 32 | 33 | //生成的文件都Rename_开头 34 | db.ClassGenerating.CreateClassFiles(db, ("e:/TestModels"), "Models", 35 | null, 36 | className => { 37 | //生成文件之后的回调 38 | }, tableName => { 39 | //生成文件之前的回调 40 | }); 41 | 42 | 43 | //只生成student和school表的实体 44 | db.ClassGenerating.CreateClassFilesByTableNames(db, "e:/TestSqliteModels2", "Models", new string[] { "student", "school" }); 45 | 46 | //根据表名生成class字符串 47 | var str = db.ClassGenerating.TableNameToClass(db, "Student"); 48 | 49 | var dynamicToClassStr = db.ClassGenerating.DynamicToClass(new { id = 1 }, "dyName"); 50 | 51 | //根据SQL语句生成class字符串 52 | var str2 = db.ClassGenerating.SqlToClass(db, "select * from Student limit 0,1", "student"); 53 | 54 | //改变值(lassTemplate.ItemTemplate=XXXX)可以自定义格式 55 | var tempItem = ClassTemplate.ItemTemplate;//例如可以在生成的实体添加默认构造函数给指定的字段赋默认值或者公司信息等 56 | var temp = ClassTemplate.Template; 57 | var temSummary = ClassTemplate.ClassFieldSummaryTemplate; 58 | 59 | 60 | //设置新格式模板 61 | //主键Guid.New(), 62 | //CreateTime为DateTime.Now 63 | //IsRemove=0 64 | //UpdateTime为DateTime.Now 65 | ClassTemplate.Template = "using System;\r\nusing System.Linq;\r\nusing System.Text;\r\n\r\nnamespace $namespace\r\n{\r\n public class $className\r\n {\r\n public $className() \r\n { \r\n this.CreateTime = DateTime.Now;\r\n this. = 0;\r\n this.UpdateTime=DateTime.Now;\r\n this.$primaryKeyName=Guid.NewGuid().ToString(\"N\").ToUpper();\r\n }\r\n $foreach\r\n }\r\n}\r\n"; 66 | 67 | //新格式的实体字符串 68 | var str3 = db.ClassGenerating.TableNameToClass(db, "Student"); 69 | 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /NewTest/Demos/Delete.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NewTest.Dao; 6 | using Models; 7 | using System.Data.SqlClient; 8 | 9 | namespace NewTest.Demos 10 | { 11 | //删除的例子 12 | public class Delete:IDemos 13 | { 14 | 15 | public void Init() 16 | { 17 | Console.WriteLine("启动Deletes.Init"); 18 | using (var db = SugarDao.GetInstance()) 19 | { 20 | 21 | 22 | //删除根据主键 23 | db.Delete(10); 24 | 25 | //删除根据表达示 26 | db.Delete(it => it.id > 100);//支持it=>array.contains(it.id) 27 | 28 | //主键批量删除 29 | db.Delete(new string[] { "100", "101", "102" }); 30 | 31 | //非主键批量删除 32 | db.Delete(it => it.name, new string[] { "" }); 33 | db.Delete(it => it.id, new int[] { 20, 22 }); 34 | 35 | 36 | //根据实体赋值实体一定要有主键,并且要有值。 37 | db.Delete(new School() { id = 200 }); 38 | 39 | //根据字符串删除 40 | db.Delete("id=@id", new { id = 100 }); 41 | 42 | //假删除 43 | //db.FalseDelete("is_del", 100); 44 | //等同于 update school set is_del=1 where id in(100) 45 | //db.FalseDelete("is_del", it=>it.id==100); 46 | 47 | 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /NewTest/Demos/EnumDemo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NewTest.Dao; 6 | using Models; 7 | using System.Data.SqlClient; 8 | using SQLiteSugar; 9 | 10 | namespace NewTest.Demos 11 | { 12 | //枚举的支持 13 | public class EnumDemo:IDemos 14 | { 15 | 16 | public void Init() 17 | { 18 | Console.WriteLine("启动EnumDemo.Init"); 19 | using (SqlSugarClient db = SugarDao.GetInstance()) 20 | { 21 | var stuList = db.Queryable().ToList(); 22 | db.Insert(new Student() { sch_id = SchoolEnum.北大青鸟 }); 23 | db.Update(new Student() { sch_id = SchoolEnum.it清华, id = 11 }); 24 | var stuList2 = db.Queryable().Where(it => it.sch_id == SchoolEnum.全智).ToList(); 25 | } 26 | } 27 | public class Student 28 | { 29 | 30 | /// 31 | /// 说明:- 32 | /// 默认:- 33 | /// 可空:False 34 | /// 35 | public int id { get; set; } 36 | 37 | /// 38 | /// 说明:- 39 | /// 默认:- 40 | /// 可空:True 41 | /// 42 | public string name { get; set; } 43 | 44 | /// 45 | /// 说明:- 46 | /// 默认:- 47 | /// 可空:False 48 | /// 49 | public SchoolEnum sch_id { get; set; } 50 | 51 | /// 52 | /// 说明:- 53 | /// 默认:- 54 | /// 可空:True 55 | /// 56 | public string sex { get; set; } 57 | 58 | /// 59 | /// 说明:- 60 | /// 默认:- 61 | /// 可空:False 62 | /// 63 | public bool isOk { get; set; } 64 | 65 | } 66 | 67 | public enum SchoolEnum 68 | { 69 | 北大青鸟 = 1, 70 | it清华 = 2, 71 | 全智 = 3 72 | } 73 | } 74 | 75 | 76 | 77 | } 78 | -------------------------------------------------------------------------------- /NewTest/Demos/Filter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NewTest.Dao; 6 | using Models; 7 | using System.Data.SqlClient; 8 | using SQLiteSugar; 9 | 10 | namespace NewTest.Demos 11 | { 12 | //过滤器用法 13 | //使用场合(例如:假删除查询,这个时候就可以设置一个过滤器,不需要每次都 .Where(it=>it.IsDelete==true)) 14 | public class Filter : IDemos 15 | { 16 | 17 | public void Init() 18 | { 19 | Console.WriteLine("启动Filter.Init"); 20 | using (SqlSugarClient db = SugarDaoFilter.GetInstance())//开启数据库连接 21 | { 22 | //设置走哪个过滤器 23 | db.CurrentFilterKey = "role,role2"; //支持多个过滤器以逗号隔开 24 | 25 | //queryable 26 | var list = db.Queryable().ToList(); //通过全局过滤器对需要权限验证的数据进行过滤 27 | //相当于db.Queryable().Where("id=@id",new{id=1}) 28 | 29 | 30 | //sqlable 31 | var list2 = db.Sqlable().From("s").SelectToList("*"); 32 | //同上 33 | 34 | //sqlQuery 35 | var list3 = db.SqlQuery("select * from Student WHERE 1=1"); 36 | //同上 37 | } 38 | } 39 | /// 40 | /// 扩展SqlSugarClient 41 | /// 42 | public class SugarDaoFilter 43 | { 44 | //禁止实例化 45 | private SugarDaoFilter() 46 | { 47 | 48 | } 49 | /// 50 | /// 页面所需要的过滤函数 51 | /// 52 | private static Dictionary> _filterParas = new Dictionary>() 53 | { 54 | { "role",()=>{ 55 | return new KeyValueObj(){ Key=" id=@id" , Value=new{ id=1}}; 56 | } 57 | }, 58 | { "role2",()=>{ 59 | return new KeyValueObj(){ Key=" id>0"}; 60 | } 61 | }, 62 | }; 63 | public static SqlSugarClient GetInstance() 64 | { 65 | string connection = SugarDao.ConnectionString; //这里可以动态根据cookies或session实现多库切换 66 | var db = new SqlSugarClient(connection); 67 | db.SetFilterItems(_filterParas); 68 | 69 | db.IsEnableLogEvent = true;//启用日志事件 70 | db.LogEventStarting = (sql, par) => { Console.WriteLine(sql + " " + par + "\r\n"); }; 71 | return db; 72 | } 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /NewTest/Demos/Filter2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NewTest.Dao; 6 | using Models; 7 | using System.Data.SqlClient; 8 | using SQLiteSugar; 9 | 10 | namespace NewTest.Demos 11 | { 12 | //行过滤加列过滤 13 | //权限管理的最佳设计 14 | public class Filter2 : IDemos 15 | { 16 | 17 | public void Init() 18 | { 19 | Console.WriteLine("启动Filter2.Init"); 20 | using (SqlSugarClient db = SugarDaoFilter.GetInstance())//开启数据库连接 21 | { 22 | //设置走哪个过滤器 23 | db.CurrentFilterKey = "role1"; 24 | //queryable 25 | var list = db.Queryable().ToJson(); //where id=1 , 可以查看id和name 26 | 27 | 28 | //设置走哪个过滤器 29 | db.CurrentFilterKey = "role2"; 30 | //queryable 31 | var list2 = db.Queryable().ToJson(); //where id=2 , 可以查看name 32 | 33 | } 34 | } 35 | /// 36 | /// 扩展SqlSugarClient 37 | /// 38 | public class SugarDaoFilter 39 | { 40 | //禁止实例化 41 | private SugarDaoFilter() 42 | { 43 | 44 | } 45 | /// 46 | /// 页面所需要的过滤行 47 | /// 48 | private static Dictionary> _filterRos = new Dictionary>() 49 | { 50 | { "role1",()=>{ 51 | return new KeyValueObj(){ Key=" id=@id" , Value=new{ id=1}}; 52 | } 53 | }, 54 | { "role2",()=>{ 55 | return new KeyValueObj() { Key = " id=@id", Value = new { id = 2 } }; 56 | } 57 | }, 58 | }; 59 | /// 60 | /// 页面所需要的过滤列 61 | /// 62 | private static Dictionary> _filterColumns = new Dictionary>() 63 | { 64 | { "role1",new List(){"id","name"} 65 | }, 66 | { "role2",new List(){"name"} 67 | }, 68 | }; 69 | public static SqlSugarClient GetInstance() 70 | { 71 | string connection = SugarDao.ConnectionString; //这里可以动态根据cookies或session实现多库切换 72 | var db = new SqlSugarClient(connection); 73 | 74 | //支持sqlable和queryable 75 | db.SetFilterItems(_filterRos); 76 | 77 | //列过滤只支持queryable 78 | db.SetFilterItems(_filterColumns); 79 | 80 | 81 | db.IsEnableLogEvent = true;//启用日志事件 82 | db.LogEventStarting = (sql, par) => { Console.WriteLine(sql + " " + par + "\r\n"); }; 83 | return db; 84 | } 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /NewTest/Demos/IDemos.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | namespace NewTest.Demos 6 | { 7 | public interface IDemos 8 | { 9 | void Init(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /NewTest/Demos/IgnoreErrorColumns.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NewTest.Dao; 6 | using Models; 7 | using System.Data.SqlClient; 8 | using SQLiteSugar; 9 | 10 | namespace NewTest.Demos 11 | { 12 | //排除错误列 13 | public class IgnoreErrorColumns : IDemos 14 | { 15 | 16 | public void Init() 17 | { 18 | Console.WriteLine("启动IgnoreErrorColumns.Init"); 19 | using (var db = SugarDao.GetInstance()) 20 | { 21 | db.IsIgnoreErrorColumns = true; 22 | 23 | //Student表并没有 AreaName 24 | var id= db.Insert(new STUDENT() { name = "张三", AreaName = "北大" }); 25 | 26 | 27 | db.Update(new STUDENT() { id=id.ObjToInt() ,name = "张三2", AreaName = "北大" }); 28 | } 29 | } 30 | public class STUDENT { 31 | /// 32 | /// Desc:- 33 | /// Default:- 34 | /// Nullable:False 35 | /// 36 | public int id { get; set; } 37 | 38 | /// 39 | /// Desc:- 40 | /// Default:- 41 | /// Nullable:True 42 | /// 43 | public string name { get; set; } 44 | 45 | /// 46 | /// Desc:学校ID 47 | /// Default:- 48 | /// Nullable:True 49 | /// 50 | public int? sch_id { get; set; } 51 | 52 | /// 53 | /// Desc:- 54 | /// Default:- 55 | /// Nullable:True 56 | /// 57 | public string sex { get; set; } 58 | 59 | /// 60 | /// Desc:- 61 | /// Default:- 62 | /// Nullable:True 63 | /// 64 | public Boolean? isOk { get; set; } 65 | 66 | public string SchoolName { get; set; } 67 | 68 | public string AreaName { get; set; } 69 | 70 | public string SubjectName { get; set; } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /NewTest/Demos/InitConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NewTest.Dao; 6 | using Models; 7 | using System.Data.SqlClient; 8 | using SQLiteSugar; 9 | 10 | namespace NewTest.Demos 11 | { 12 | /// 13 | ///如何避免初始化SqlSugarClient时,参数赋值引起的性能的浪费 14 | /// 15 | public class InitConfig : IDemos 16 | { 17 | 18 | public void Init() 19 | { 20 | Console.WriteLine("启动InitConfig.Init"); 21 | using (SqlSugarClient db = SugarPocoDao.GetInstance())//开启数据库连接 22 | { 23 | 24 | } 25 | } 26 | 27 | /// 28 | /// SqlSugarClient初始化全配置类 29 | /// 30 | public class DaoInitConfig 31 | { 32 | //别名列 33 | public static List columnMappingList= new List() { 34 | new KeyValue(){ Key="entityId", Value="tableId"}, 35 | new KeyValue(){ Key="entityName", Value="tableName"} 36 | }; 37 | 38 | //别名表 39 | public static List tableMappingList = null; 40 | 41 | 42 | //流水号 43 | public static List serialNumber = new List(){ 44 | new PubModel.SerialNumber(){TableName="Student", FieldName="name", GetNumFunc=()=>{ return "stud-"+DateTime.Now.ToString("yyyy-MM-dd");}}, 45 | new PubModel.SerialNumber(){TableName="School", FieldName="name", GetNumFuncWithDb=db=>{ return "ch-"+DateTime.Now.ToString("syyyy-MM-dd"); }} 46 | }; 47 | 48 | //自动排除非数据库列 49 | public static bool IsIgnoreErrorColumns=true; 50 | 51 | } 52 | 53 | 54 | /// 55 | /// 扩展SqlSugarClient 56 | /// 57 | public class SugarPocoDao 58 | { 59 | //禁止实例化 60 | private SugarPocoDao() 61 | { 62 | 63 | } 64 | 65 | public static SqlSugarClient GetInstance() 66 | { 67 | 68 | string connection = SugarDao.ConnectionString; //这里可以动态根据cookies或session实现多库切换 69 | var db = new SqlSugarClient(connection); 70 | 71 | /**这种写法只给db对象添加了4个指向地址(DaoInitConfig变量都为静态对象),并非指向内容,指向内容初始化后存储在内存当中,所以性能就不用说了 **/ 72 | 73 | db.SetMappingTables(GetMappingTables(db));//设置别名表 74 | 75 | db.SetMappingColumns(DaoInitConfig.columnMappingList);//设置别名列 76 | 77 | db.SetSerialNumber(DaoInitConfig.serialNumber);//设置流水号 78 | 79 | db.IsIgnoreErrorColumns = DaoInitConfig.IsIgnoreErrorColumns; //自动排除非数据库列 80 | 81 | 82 | return db; 83 | } 84 | 85 | /// 86 | /// 批量设置别名表 87 | /// 88 | /// 89 | /// 90 | private static List GetMappingTables(SqlSugarClient db) 91 | { 92 | if (DaoInitConfig.tableMappingList == null) 93 | { 94 | DaoInitConfig.tableMappingList = new List(); 95 | db.ClassGenerating.ForeachTables(db, name =>//内置遍历表名和视图名函数 96 | { 97 | //给所有表名加dbo. 98 | DaoInitConfig.tableMappingList.Add(new KeyValue() { Key = name, Value ="dbo."+name }); 99 | 100 | //动态获取sechma 101 | // DaoInitConfig.tableMappingList.Add(new KeyValue() { Key = name, Value = db.ClassGenerating.GetTableNameWithSchema(db,name) }); 102 | }); 103 | } 104 | return DaoInitConfig.tableMappingList; 105 | } 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /NewTest/Demos/Insert.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NewTest.Dao; 6 | using Models; 7 | using System.Data.SqlClient; 8 | using SQLiteSugar; 9 | namespace NewTest.Demos 10 | { 11 | //插入 12 | public class Insert : IDemos 13 | { 14 | 15 | public void Init() 16 | { 17 | Console.WriteLine("启动Inset.Init"); 18 | using (var db = SugarDao.GetInstance()) 19 | { 20 | 21 | db.Insert(GetInsertItem()); //插入一条记录 (有主键也好,没主键也好,有自增列也好都可以插进去) 22 | 23 | 24 | db.InsertRange(GetInsertList()); //批量插入 支持(别名表等功能) 25 | 26 | 27 | db.SqlBulkCopy(GetInsertList()); //批量插入 适合海量数据插入 28 | 29 | 30 | 31 | //设置不插入列 32 | db.DisableInsertColumns = new string[] { "sex" };//sex列将不会插入值 33 | Student s = new Student() 34 | { 35 | name = "张" + new Random().Next(1, int.MaxValue), 36 | sex = "gril" 37 | }; 38 | 39 | var id = db.Insert(s); //插入 40 | 41 | //查询刚插入的sex是否有值 42 | var sex = db.Queryable().Single(it => it.id == id.ObjToInt()).sex;//无值 43 | var name = db.Queryable().Single(it => it.id == id.ObjToInt()).name;//有值 44 | 45 | 46 | //SqlBulkCopy同样支持不挺入列设置 47 | db.SqlBulkCopy(GetInsertList()); 48 | } 49 | } 50 | 51 | private static List GetInsertList() 52 | { 53 | List list = new List() 54 | { 55 | new Student() 56 | { 57 | name="张"+new Random().Next(1,int.MaxValue), 58 | isOk=true, 59 | sch_id=1 60 | }, 61 | new Student() 62 | { 63 | name="张"+new Random().Next(1,int.MaxValue), 64 | isOk=false, 65 | sch_id=2 66 | } 67 | }; 68 | return list; 69 | } 70 | 71 | private static Student GetInsertItem() 72 | { 73 | Student s = new Student() 74 | { 75 | name = "张" + new Random().Next(1, int.MaxValue) 76 | }; 77 | return s; 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /NewTest/Demos/Log.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NewTest.Dao; 6 | using Models; 7 | using System.Data.SqlClient; 8 | using SQLiteSugar; 9 | 10 | namespace NewTest.Demos 11 | { 12 | //日志记录功能 13 | public class Log : IDemos 14 | { 15 | 16 | public void Init() 17 | { 18 | Console.WriteLine("启动Log.Init"); 19 | using (var db = SugarDemoDao.GetInstance()) 20 | { 21 | 22 | var a1 = db.Queryable().Where(it => it.id == 1).ToList(); 23 | var a2 = db.Queryable().OrderBy(it => it.id).ToList(); 24 | } 25 | } 26 | 27 | public class SugarConfigs 28 | { 29 | public static Action LogEventStarting = (sql, pars) => 30 | { 31 | Console.WriteLine("starting:" + sql + " " + pars); 32 | 33 | using (var db = SugarDemoDao.GetInstance()) 34 | { 35 | //日志记录件事件里面用到数据库操作 IsEnableLogEvent一定要为false否则将引起死循环,并且要新开一个数据实例 像我这样写就没问题。 36 | db.IsEnableLogEvent = false; 37 | db.ExecuteCommand("select 1"); 38 | } 39 | }; 40 | public static Action LogEventCompleted = (sql, pars) => 41 | { 42 | Console.WriteLine("completed:" + sql + " " + pars); 43 | }; 44 | } 45 | 46 | /// 47 | /// SqlSugar 48 | /// 49 | public class SugarDemoDao 50 | { 51 | 52 | public static SqlSugarClient GetInstance() 53 | { 54 | var db = new SqlSugarClient(SugarDao.ConnectionString); 55 | db.IsEnableLogEvent = true;//启用日志事件 56 | db.LogEventStarting = SugarConfigs.LogEventStarting; 57 | db.LogEventCompleted = SugarConfigs.LogEventCompleted; 58 | return db; 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /NewTest/Demos/MappingColumns.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NewTest.Dao; 6 | using System.Data.SqlClient; 7 | using SQLiteSugar; 8 | namespace NewTest.Demos 9 | { 10 | //别名列的功能 11 | public class MappingColumns : IDemos 12 | { 13 | 14 | public void Init() 15 | { 16 | Console.WriteLine("启动MappingColumns.Init"); 17 | 18 | //全局设置 19 | using (var db = SugarFactory.GetInstance()) 20 | { 21 | var list = db.Queryable().Where(it=>it.classId==1).ToList(); 22 | } 23 | } 24 | 25 | public class Student 26 | { 27 | 28 | //id 29 | public int classId { get; set; } 30 | 31 | //name 32 | public string className { get; set; } 33 | 34 | //sch_id 35 | public int classSchoolId { get; set; } 36 | 37 | public int isOk { get; set; } 38 | } 39 | 40 | /// 41 | /// 全局配置别名列(不区分表) 42 | /// 43 | public class SugarConfigs 44 | { 45 | //key实体字段名 value表字段名 ,KEY唯一否则异常 46 | public static List MpList = new List(){ 47 | new KeyValue(){ Key="classId", Value="id"}, 48 | new KeyValue(){ Key="className", Value="name"}, 49 | new KeyValue(){ Key="classSchoolId", Value="sch_id"} 50 | }; 51 | } 52 | 53 | /// 54 | /// SqlSugar实例工厂 55 | /// 56 | public class SugarFactory 57 | { 58 | 59 | //禁止实例化 60 | private SugarFactory() 61 | { 62 | 63 | } 64 | public static SqlSugarClient GetInstance() 65 | { 66 | string connection = SugarDao.ConnectionString; //这里可以动态根据cookies或session实现多库切换 67 | var db = new SqlSugarClient(connection); 68 | //注意:只有启动属性映射才可以使用SetMappingColumns 69 | db.IsEnableAttributeMapping = true; 70 | db.SetMappingColumns(SugarConfigs.MpList);//设置关联列 (引用地址赋值,每次赋值都只是存储一个内存地址) 71 | return db; 72 | } 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /NewTest/Demos/MappingTable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NewTest.Dao; 6 | using Models; 7 | using System.Data.SqlClient; 8 | using SQLiteSugar; 9 | namespace NewTest.Demos 10 | { 11 | //别名表的功能 12 | public class MappingTable : IDemos 13 | { 14 | 15 | public void Init() 16 | { 17 | Console.WriteLine("启动MappingTable.Init"); 18 | 19 | //单个设置 20 | using (var db = SugarDao.GetInstance()) 21 | { 22 | var list = db.Queryable("Student").ToList();//查询的是 select * from student 而我的实体名称为V_Student 23 | } 24 | 25 | 26 | //全局设置 27 | using (var db = SugarFactory.GetInstance()) 28 | { 29 | var list = db.Queryable().ToList();//查询的是 select * from student 而我的实体名称为V_Student 30 | } 31 | } 32 | 33 | 34 | /// 35 | /// 全局配置类 36 | /// 37 | public class SugarConfigs 38 | { 39 | //key类名 value表名 40 | public static List MpList = new List(){ 41 | new KeyValue(){ Key="FormAttr", Value="Flow_FormAttr"}, 42 | new KeyValue(){ Key="Student3", Value="Student"}, 43 | new KeyValue(){ Key="V_Student", Value="Student"} 44 | }; 45 | } 46 | 47 | /// 48 | /// SqlSugar实例工厂 49 | /// 50 | public class SugarFactory 51 | { 52 | 53 | //禁止实例化 54 | private SugarFactory() 55 | { 56 | 57 | } 58 | public static SqlSugarClient GetInstance() 59 | { 60 | string connection = SugarDao.ConnectionString; //这里可以动态根据cookies或session实现多库切换 61 | var db = new SqlSugarClient(connection); 62 | 63 | db.SetMappingTables(SugarConfigs.MpList);//设置关联表 (引用地址赋值,每次赋值都只是存储一个内存地址) 64 | 65 | 66 | 67 | //批量设置别名表 68 | //db.ClassGenerating.ForeachTables(db, tableName => 69 | //{ 70 | // db.AddMappingTable(new KeyValue() { Key = tableName.Replace("bbs.",""), Value = tableName }); //key实体名,value表名 71 | //}); 72 | 73 | 74 | return db; 75 | } 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /NewTest/Demos/PubMethod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NewTest.Dao; 6 | using Models; 7 | using System.Data.SqlClient; 8 | using SQLiteSugar; 9 | namespace NewTest.Demos 10 | { 11 | //公用函数 12 | public class PubMethod:IDemos 13 | { 14 | 15 | public void Init() 16 | { 17 | Console.WriteLine("启动PubMethod.Init"); 18 | using (var db = SugarDao.GetInstance()) 19 | { 20 | //ToJoinSqlInVal 21 | var par = new string[] { "a", "c", "3" }; 22 | var ids = par.ToJoinSqlInVal();//将数组转成 'a','c','3' 有防SQL注入处理 23 | 24 | 25 | //ToSqlValue 26 | try 27 | { 28 | var par2 = "a'"; 29 | var newpar2 = par2.ToSqlValue();//对字符串防注入处理 30 | } 31 | catch (Exception ex) 32 | { 33 | 34 | Console.WriteLine(ex.Message); 35 | } 36 | 37 | //SqlLikeWordEncode 处理LIKE特殊字符 38 | var likestr = SqlSugarTool.SqlLikeWordEncode("[%%%"); 39 | 40 | 41 | //GetParameterArray 获取页面参数所有参数的键和值 42 | var pars = SqlSugarTool.GetParameterArray(); 43 | 44 | 45 | //将匿名对象转成SqlParameter 46 | var par3 = SqlSugarTool.GetParameters(new { id = 1 }); 47 | 48 | 49 | //用于生成多语言的视图 50 | //LanguageHelper.UpdateView() 51 | 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /NewTest/Demos/SerialNumber.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NewTest.Dao; 6 | using Models; 7 | using System.Data.SqlClient; 8 | using SQLiteSugar; 9 | 10 | namespace NewTest.Demos 11 | { 12 | //流水号的功能 13 | public class SerialNumber : IDemos 14 | { 15 | 16 | public void Init() 17 | { 18 | Console.WriteLine("启动SerialNumber.Init"); 19 | using (SqlSugarClient db = SugarFactory.GetInstance())//开启数据库连接 20 | { 21 | var dientityValue = db.Insert(new Student() { }); 22 | var name = db.Queryable().Single(it => it.id == dientityValue.ObjToInt()).name; 23 | Console.WriteLine(name); 24 | 25 | var dientityValue2 = db.Insert(new School() { }); 26 | var name2 = db.Queryable().Single(it => it.id == dientityValue2.ObjToInt()).name; 27 | Console.WriteLine(name2); ; 28 | } 29 | } 30 | 31 | /// 32 | /// 全局配置类 33 | /// 34 | public class SugarConfigs 35 | { 36 | public static List NumList = new List(){ 37 | new PubModel.SerialNumber(){TableName="Student", FieldName="name", GetNumFunc=()=>{ //GetNumFunc在没有事中使用 38 | return "stud-"+DateTime.Now.ToString("yyyy-MM-dd"); 39 | }}, 40 | new PubModel.SerialNumber(){TableName="School", FieldName="name", GetNumFuncWithDb=db=>{ //事务中请使用GetNumFuncWithDb保证同一个DB对象,不然会出现死锁 41 | return "ch-"+DateTime.Now.ToString("syyyy-MM-dd"); 42 | }} 43 | }; 44 | } 45 | 46 | /// 47 | /// SqlSugar实例工厂 48 | /// 49 | public class SugarFactory 50 | { 51 | 52 | //禁止实例化 53 | private SugarFactory() 54 | { 55 | 56 | } 57 | public static SqlSugarClient GetInstance() 58 | { 59 | string connection = SugarDao.ConnectionString; //这里可以动态根据cookies或session实现多库切换 60 | var db = new SqlSugarClient(connection); 61 | db.SetSerialNumber(SugarConfigs.NumList);//设置流水号 62 | return db; 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /NewTest/Demos/SerializerDateFormat.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NewTest.Dao; 6 | using Models; 7 | using System.Data.SqlClient; 8 | using SQLiteSugar; 9 | 10 | namespace NewTest.Demos 11 | { 12 | //设置ToJson的日期格式 13 | public class SerializerDateFormat : IDemos 14 | { 15 | 16 | public void Init() 17 | { 18 | Console.WriteLine("启动SerializerDateFormat.Init"); 19 | using (SqlSugarClient db = SugarDao.GetInstance()) 20 | { 21 | db.SerializerDateFormat = "yyyy-mm/dd"; 22 | var jsonStr = db.Queryable().OrderBy("id").Take(1).ToJson(); 23 | var jsonStr2 = db.Sqlable().From("t").SelectToJson(" top 1 *"); 24 | var jsonStr3 = db.SqlQueryJson("select top 1 * from InsertTest"); 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /NewTest/Demos/Tran.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NewTest.Dao; 6 | using Models; 7 | using System.Data.SqlClient; 8 | using SQLiteSugar; 9 | 10 | namespace NewTest.Demos 11 | { 12 | //事务 13 | public class Tran : IDemos 14 | { 15 | 16 | public void Init() 17 | { 18 | Console.WriteLine("启动Tran.Init"); 19 | using (SqlSugarClient db = SugarDao.GetInstance())//开启数据库连接 20 | { 21 | db.CommandTimeOut = 30000;//设置超时时间 22 | try 23 | { 24 | db.BeginTran();//开启事务 25 | //db.BeginTran(IsolationLevel.ReadCommitted);+3重载可以设置事世隔离级别 26 | 27 | db.CommitTran();//提交事务 28 | } 29 | catch (Exception) 30 | { 31 | db.RollbackTran();//回滚事务 32 | throw; 33 | } 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /NewTest/Demos/Update.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NewTest.Dao; 6 | using Models; 7 | using System.Data.SqlClient; 8 | 9 | namespace NewTest.Demos 10 | { 11 | //更新 12 | public class Update : IDemos 13 | { 14 | 15 | public void Init() 16 | { 17 | Console.WriteLine("启动Ado.Update"); 18 | using (var db = SugarDao.GetInstance()) 19 | { 20 | 21 | //指定列更新 22 | db.Update(new { name = "蓝翔14" }, it => it.id == 14); //只更新name列 23 | db.Update(new { name = "蓝翔11 23 12", areaId = 2 }, 11, 23, 12); 24 | db.Update(new { name = "蓝翔2" }, new string[] { "11", "21" }); 25 | db.Update(new { name = "蓝翔2" }, it => it.id == 100); 26 | var array=new int[]{1,2,3}; 27 | db.Update(new { name = "蓝翔2" }, it => array.Contains(it.id));// id in 1,2,3 28 | 29 | 30 | //支持字典更新,适合动态权限 31 | var dic = new Dictionary(); 32 | dic.Add("name", "第十三条"); 33 | dic.Add("areaId", "1"); 34 | db.Update(dic, 13); 35 | 36 | 37 | //整个实体更新 38 | db.Update(new School { id = 16, name = "蓝翔16", AreaId = 1 }); 39 | db.Update(new School { id = 12, name = "蓝翔12", AreaId = 2 }, it => it.id == 18); 40 | db.Update(new School() { id = 11, name = "青鸟11" }); 41 | 42 | //设置不更新列 43 | db.DisableUpdateColumns = new string[] { "CreateTime" };//设置CreateTime不更新 44 | 45 | TestUpdateColumns updObj = new TestUpdateColumns() 46 | { 47 | VGUID = Guid.Parse("542b5a27-6984-47c7-a8ee-359e483c8470"), 48 | Name = "xx", 49 | Name2 = "xx2", 50 | IdentityField = 0, 51 | CreateTime = null 52 | }; 53 | 54 | //CreateTime将不会被更新 55 | db.Update(updObj); 56 | //以前实现这种更新需要用指定列的方式实现,现在就简单多了。 57 | 58 | 59 | 60 | //批量更新 数据量小时建议使用 61 | var updateResult = db.UpdateRange(GetUpdateList()); 62 | 63 | //批量更新 数据量大时建议使用 64 | var updateResult2 = db.SqlBulkReplace(GetUpdateList2()); 65 | 66 | 67 | //更新字符串 68 | db.Update("sch_id=sch_id+1", it => it.id == 1); 69 | 70 | 71 | //清空禁止更新列 72 | db.DisableUpdateColumns = null; 73 | //新语法添加禁止更新列 74 | db.AddDisableUpdateColumns("id", "name");//添加禁止更新列 75 | } 76 | } 77 | 78 | 79 | 80 | private static List GetUpdateList() 81 | { 82 | List list = new List() 83 | { 84 | new Student() 85 | { 86 | id=1001, 87 | name="1张1001"+new Random().Next(1,int.MaxValue) 88 | }, 89 | new Student() 90 | { 91 | id=1002, 92 | name="1张1002"+new Random().Next(1,int.MaxValue) 93 | } 94 | }; 95 | return list; 96 | } 97 | private static List GetUpdateList2() 98 | { 99 | List list = new List() 100 | { 101 | new Student() 102 | { 103 | id=1010, 104 | name="小妹"+new Random().Next(1,int.MaxValue), 105 | isOk=false, 106 | sch_id=2, 107 | sex="gril" 108 | }, 109 | new Student() 110 | { 111 | id=1011, 112 | name="小子"+new Random().Next(1,int.MaxValue), 113 | isOk=true, 114 | sch_id=3, 115 | sex="boy" 116 | } 117 | }; 118 | return list; 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /NewTest/Models/Area.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Text; 4 | 5 | namespace Models 6 | { 7 | public class Area 8 | { 9 | 10 | /// 11 | /// Desc:- 12 | /// Default:- 13 | /// Nullable:False 14 | /// 15 | public int id {get;set;} 16 | 17 | /// 18 | /// Desc:- 19 | /// Default:- 20 | /// Nullable:True 21 | /// 22 | public string name {get;set;} 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /NewTest/Models/InsertTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Text; 4 | 5 | namespace Models 6 | { 7 | public class InsertTest 8 | { 9 | 10 | /// 11 | /// Desc:- 12 | /// Default:- 13 | /// Nullable:False 14 | /// 15 | public int id {get;set;} 16 | 17 | /// 18 | /// Desc:- 19 | /// Default:- 20 | /// Nullable:True 21 | /// 22 | public string v1 {get;set;} 23 | 24 | /// 25 | /// Desc:- 26 | /// Default:- 27 | /// Nullable:True 28 | /// 29 | public string v2 {get;set;} 30 | 31 | /// 32 | /// Desc:- 33 | /// Default:- 34 | /// Nullable:True 35 | /// 36 | public string v3 {get;set;} 37 | 38 | /// 39 | /// Desc:- 40 | /// Default:- 41 | /// Nullable:True 42 | /// 43 | public int? int1 {get;set;} 44 | 45 | /// 46 | /// Desc:- 47 | /// Default:- 48 | /// Nullable:True 49 | /// 50 | public DateTime? d1 {get;set;} 51 | 52 | /// 53 | /// Desc:- 54 | /// Default:- 55 | /// Nullable:True 56 | /// 57 | public string txt {get;set;} 58 | 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /NewTest/Models/LanguageTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Text; 4 | 5 | namespace Models 6 | { 7 | public class LanguageTest 8 | { 9 | 10 | /// 11 | /// Desc:- 12 | /// Default:- 13 | /// Nullable:False 14 | /// 15 | public int Id {get;set;} 16 | 17 | /// 18 | /// Desc:- 19 | /// Default:- 20 | /// Nullable:True 21 | /// 22 | public int? LanguageId {get;set;} 23 | 24 | /// 25 | /// Desc:- 26 | /// Default:- 27 | /// Nullable:True 28 | /// 29 | public string Name {get;set;} 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /NewTest/Models/School.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Text; 4 | 5 | namespace Models 6 | { 7 | public class School 8 | { 9 | 10 | /// 11 | /// Desc:地域ID,关联area表 12 | /// Default:- 13 | /// Nullable:False 14 | /// 15 | public int id {get;set;} 16 | 17 | /// 18 | /// Desc:- 19 | /// Default:- 20 | /// Nullable:True 21 | /// 22 | public string name {get;set;} 23 | 24 | /// 25 | /// Desc:- 26 | /// Default:- 27 | /// Nullable:True 28 | /// 29 | public int? AreaId {get;set;} 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /NewTest/Models/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Text; 4 | 5 | namespace Models 6 | { 7 | public class Student 8 | { 9 | 10 | /// 11 | /// Desc:- 12 | /// Default:- 13 | /// Nullable:False 14 | /// 15 | public int id {get;set;} 16 | 17 | /// 18 | /// Desc:- 19 | /// Default:- 20 | /// Nullable:True 21 | /// 22 | public string name {get;set;} 23 | 24 | /// 25 | /// Desc:学校ID 26 | /// Default:- 27 | /// Nullable:True 28 | /// 29 | public int? sch_id {get;set;} 30 | 31 | /// 32 | /// Desc:- 33 | /// Default:- 34 | /// Nullable:True 35 | /// 36 | public string sex {get;set;} 37 | 38 | /// 39 | /// Desc:- 40 | /// Default:- 41 | /// Nullable:True 42 | /// 43 | public Boolean? isOk {get;set;} 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /NewTest/Models/Student2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Text; 4 | 5 | namespace Models 6 | { 7 | public class Student2 8 | { 9 | 10 | /// 11 | /// Desc:- 12 | /// Default:- 13 | /// Nullable:False 14 | /// 15 | public int id { get; set; } 16 | 17 | /// 18 | /// Desc:- 19 | /// Default:- 20 | /// Nullable:True 21 | /// 22 | public string name { get; set; } 23 | 24 | /// 25 | /// Desc:学校ID 26 | /// Default:- 27 | /// Nullable:True 28 | /// 29 | public int sch_id { get; set; } 30 | 31 | /// 32 | /// Desc:- 33 | /// Default:- 34 | /// Nullable:True 35 | /// 36 | public string sex { get; set; } 37 | 38 | /// 39 | /// Desc:- 40 | /// Default:- 41 | /// Nullable:True 42 | /// 43 | public Boolean isOk { get; set; } 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /NewTest/Models/StudentGroup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Models 7 | { 8 | public class StudentGroup 9 | { 10 | public string Sex { get; set; } 11 | public int Count { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NewTest/Models/Subject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Text; 4 | 5 | namespace Models 6 | { 7 | public class Subject 8 | { 9 | 10 | /// 11 | /// Desc:- 12 | /// Default:- 13 | /// Nullable:False 14 | /// 15 | public int id {get;set;} 16 | 17 | /// 18 | /// Desc:学生ID 19 | /// Default:- 20 | /// Nullable:True 21 | /// 22 | public int? studentId {get;set;} 23 | 24 | /// 25 | /// Desc:- 26 | /// Default:- 27 | /// Nullable:True 28 | /// 29 | public string name {get;set;} 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /NewTest/Models/Test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Text; 4 | 5 | namespace Models 6 | { 7 | public class Test 8 | { 9 | 10 | public Int64 Id {get;set;} 11 | 12 | public DateTime Date {get;set;} 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /NewTest/Models/TestUpdateColumns.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Text; 4 | 5 | namespace Models 6 | { 7 | public class TestUpdateColumns 8 | { 9 | 10 | /// 11 | /// Desc:- 12 | /// Default:- 13 | /// Nullable:False 14 | /// 15 | public Guid VGUID {get;set;} 16 | 17 | /// 18 | /// Desc:- 19 | /// Default:- 20 | /// Nullable:False 21 | /// 22 | public int IdentityField {get;set;} 23 | 24 | /// 25 | /// Desc:- 26 | /// Default:- 27 | /// Nullable:True 28 | /// 29 | public string Name {get;set;} 30 | 31 | /// 32 | /// Desc:- 33 | /// Default:- 34 | /// Nullable:True 35 | /// 36 | public string Name2 {get;set;} 37 | 38 | /// 39 | /// Desc:- 40 | /// Default:- 41 | /// Nullable:True 42 | /// 43 | public DateTime? CreateTime {get;set;} 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /NewTest/Models/V_LanguageTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Text; 4 | 5 | namespace Models 6 | { 7 | public class V_LanguageTest 8 | { 9 | 10 | /// 11 | /// Desc:- 12 | /// Default:- 13 | /// Nullable:False 14 | /// 15 | public int Id {get;set;} 16 | 17 | /// 18 | /// Desc:- 19 | /// Default:- 20 | /// Nullable:True 21 | /// 22 | public int? LanguageId {get;set;} 23 | 24 | /// 25 | /// Desc:- 26 | /// Default:- 27 | /// Nullable:True 28 | /// 29 | public string Name {get;set;} 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /NewTest/Models/V_Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Models 7 | { 8 | public class V_Student 9 | { 10 | 11 | /// 12 | /// Desc:- 13 | /// Default:- 14 | /// Nullable:False 15 | /// 16 | public int id { get; set; } 17 | 18 | /// 19 | /// Desc:- 20 | /// Default:- 21 | /// Nullable:True 22 | /// 23 | public string name { get; set; } 24 | 25 | /// 26 | /// Desc:学校ID 27 | /// Default:- 28 | /// Nullable:True 29 | /// 30 | public int? sch_id { get; set; } 31 | 32 | /// 33 | /// Desc:- 34 | /// Default:- 35 | /// Nullable:True 36 | /// 37 | public string sex { get; set; } 38 | 39 | /// 40 | /// Desc:- 41 | /// Default:- 42 | /// Nullable:True 43 | /// 44 | public Boolean? isOk { get; set; } 45 | 46 | public string SchoolName { get; set; } 47 | 48 | public string AreaName { get; set; } 49 | 50 | public string SubjectName { get; set; } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /NewTest/NewTest.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | x86 6 | 8.0.30703 7 | 2.0 8 | {EAFE7F79-ABB5-41BA-92A1-1B8764C8885C} 9 | Exe 10 | Properties 11 | NewTest 12 | NewTest 13 | v4.0 14 | 15 | 16 | 512 17 | 18 | 19 | x86 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | 28 | 29 | x86 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | 37 | 38 | 39 | 40 | 41 | ..\SqlSugar\Lib\System.Data.SQLite.dll 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | Always 91 | 92 | 93 | 94 | 95 | Always 96 | 97 | 98 | Always 99 | 100 | 101 | 102 | 103 | {46A17E67-7E3E-4369-9B1F-43BA34BBDAEF} 104 | SqliteSugar 105 | 106 | 107 | 108 | 115 | -------------------------------------------------------------------------------- /NewTest/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using SQLiteSugar; 6 | using NewTest.Demos; 7 | namespace NewTest 8 | { 9 | class Program 10 | { 11 | /// 12 | /// SqlSugar的功能介绍 13 | /// 14 | /// 15 | static void Main(string[] args) 16 | { 17 | 18 | //设置执行的DEMO 19 | string switchOn = "select"; 20 | IDemos demo = null; 21 | switch (switchOn) 22 | { 23 | /****************************基本功能**************************************/ 24 | //查询 25 | case "select": demo = new Select(); break; 26 | //删除 27 | case "delete": demo = new Delete(); break; 28 | //插入 29 | case "insert": demo = new Insert(); break; 30 | //更新 31 | case "update": demo = new Update(); break; 32 | //基层函数的用法 33 | case "ado": demo = new Ado(); break; 34 | //事务 35 | case "tran": demo = new Tran(); break; 36 | //创建实体函数 37 | case "createclass": demo = new CreateClass(); break; 38 | //T4生成 http://www.cnblogs.com/sunkaixuan/p/5751503.html 39 | 40 | //日志记录 41 | case "log": demo = new Log(); break; 42 | //枚举支持 43 | case "enum": demo = new EnumDemo(); break; 44 | 45 | 46 | 47 | /****************************实体映射**************************************/ 48 | //自动排除非数据库列 49 | case "ignoreerrorcolumns": demo = new IgnoreErrorColumns(); break; 50 | //别名表 51 | case "mappingtable":demo=new MappingTable(); break; 52 | //别名列 53 | case "mappingcolumns": demo = new MappingColumns(); break; 54 | //通过属性的方法设置别名表和别名字段 55 | case "attributesmapping": demo = new AttributesMapping(); break; 56 | 57 | 58 | 59 | /****************************业务应用**************************************/ 60 | //过滤器 61 | case "filter": demo = new Filter(); break; 62 | //过滤器2 63 | case "filter2": demo = new Filter2(); break; 64 | //流水号功能 65 | case "serialnumber": demo = new SerialNumber(); break; 66 | 67 | //配置与实例的用法 68 | case "initconfig": demo = new InitConfig(); break; 69 | 70 | 71 | 72 | /****************************支持**************************************/ 73 | //公开函数数 74 | case "pubmethod": demo = new PubMethod(); break; 75 | 76 | //设置ToJson的日期格式 77 | case "serializerdateformat":demo =new SerializerDateFormat();break; 78 | 79 | 80 | 81 | /****************************测试用例**************************************/ 82 | case "test": demo = new Test(); break; 83 | 84 | default: Console.WriteLine("switchOn的值错误,请输入正确的 case"); break; 85 | 86 | } 87 | //执行DEMO 88 | demo.Init(); 89 | 90 | //更多例子请查看API 91 | //http://www.cnblogs.com/sunkaixuan/p/5654695.html 92 | Console.WriteLine("执行成功请关闭窗口"); 93 | Console.ReadKey(); 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /NewTest/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过以下 6 | // 特性集控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("NewTest")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("NewTest")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, 19 | // 则将该类型上的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("694762fc-c7fb-450a-a26e-06435651bcf8")] 24 | 25 | // 程序集的版本信息由下面四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订号 31 | // 32 | // 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /NewTest/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /NewTest/x64/SQLite.Interop.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DotNetNext/SqliteSugar/475c16eedeff52864f3d5e78829e5f1b74f6535c/NewTest/x64/SQLite.Interop.dll -------------------------------------------------------------------------------- /NewTest/x86/SQLite.Interop.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DotNetNext/SqliteSugar/475c16eedeff52864f3d5e78829e5f1b74f6535c/NewTest/x86/SQLite.Interop.dll -------------------------------------------------------------------------------- /SqlSugar.sln.lnk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DotNetNext/SqliteSugar/475c16eedeff52864f3d5e78829e5f1b74f6535c/SqlSugar.sln.lnk -------------------------------------------------------------------------------- /SqlSugar/Cloud/CloudModels.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Data; 6 | using System.Threading.Tasks; 7 | 8 | namespace SQLiteSugar 9 | { 10 | 11 | /// 12 | /// 云计算连接配置 13 | /// 14 | public class CloudConnectionConfig 15 | { 16 | /// 17 | /// 处理机率,值越大机率越高 18 | /// 19 | public int Rate { get; set; } 20 | /// 21 | /// 链接字符串名称 22 | /// 23 | public string ConnectionString { get; set; } 24 | } 25 | 26 | /// 27 | /// 云搜索Task反回类 28 | /// 29 | public class CloudSearchResult 30 | { 31 | /// 32 | /// 集合 33 | /// 34 | public List Entities { get; set; } 35 | /// 36 | /// 单个对象 37 | /// 38 | public T Value { get; set; } 39 | /// 40 | /// DataTable 41 | /// 42 | public DataTable DataTable { get; set; } 43 | /// 44 | /// 连接字符串 45 | /// 46 | public string ConnectionString { get; set; } 47 | /// 48 | /// 数量 49 | /// 50 | public int Count { get; set; } 51 | } 52 | 53 | 54 | 55 | /// 56 | /// 云计扩展类 57 | /// 58 | /// 59 | public class Taskable 60 | { 61 | /// 62 | /// 任务 63 | /// 64 | public Task>[] Tasks { get; set; } 65 | /// 66 | /// sql 67 | /// 68 | public string Sql { get; set; } 69 | /// 70 | /// 数据库参数(例如:new{id=1,name="张三"}) 71 | /// 72 | public object WhereObj { get; set; } 73 | 74 | } 75 | 76 | /// 77 | /// 云计扩展类 78 | /// 79 | /// 80 | public class TaskableWithCount 81 | { 82 | /// 83 | /// 任务 84 | /// 85 | public Task>[] Tasks { get; set; } 86 | /// 87 | /// sql 88 | /// 89 | public string Sql { get; set; } 90 | /// 91 | /// 数据库参数(例如:new{id=1,name="张三"}) 92 | /// 93 | public object WhereObj { get; set; } 94 | 95 | } 96 | 97 | internal class PageRowInnerParamsResult 98 | { 99 | public DataRow Row { get; set; } 100 | public int Count { get; set; } 101 | public int PageIndex { get; set; } 102 | public int PageSize { get; set; } 103 | public int Begin { get; set; } 104 | public int End { get; set; } 105 | public string Sql { get; set; } 106 | public bool IsEqs { get; set; } 107 | public string OrderByField { get; set; } 108 | public string UnqueField { get; set; } 109 | public int RowIndex { get; set; } 110 | public bool isGreater { get; set; } 111 | public string Symbol { get; set; } 112 | public object OrderByValue { get; set; } 113 | public object UnqueValue { get; set; } 114 | public OrderByType OrderByType { get; set; } 115 | public string FullOrderByString { get; set; } 116 | public string FullOrderByStringReverse { get; set; } 117 | public object WhereObj { get; set; } 118 | public string SymbolReverse { get; set; } 119 | public int ConfigCount { get; set; } 120 | public OrderByType OrderByTypeReverse { get; set; } 121 | } 122 | 123 | internal class PageRowInnerParamsResultMultipleOrderBy 124 | { 125 | public DataRow Row { get; set; } 126 | public int Count { get; set; } 127 | public int PageIndex { get; set; } 128 | public int PageSize { get; set; } 129 | public int Begin { get; set; } 130 | public int End { get; set; } 131 | public string Sql { get; set; } 132 | public string UnqueField { get; set; } 133 | public int RowIndex { get; set; } 134 | public bool isGreater { get; set; } 135 | public object UnqueValue { get; set; } 136 | public string FullOrderByString { get; set; } 137 | public string FullOrderByStringReverse { get; set; } 138 | public object WhereObj { get; set; } 139 | public int ConfigCount { get; set; } 140 | 141 | public string orderByFieldsString { get; set; } 142 | 143 | public List OrderByTypes { get; set; } 144 | 145 | public int SampleEachIndex { get; set; } 146 | } 147 | 148 | /// 149 | /// 字典排序类 150 | /// 151 | public class OrderByDictionary 152 | { 153 | /// 154 | /// 排序字段 155 | /// 156 | public string OrderByField { get; set; } 157 | /// 158 | /// 排序类型 159 | /// 160 | public OrderByType OrderByType { get; set; } 161 | /// 162 | /// 排序字符串 163 | /// 164 | public string OrderByString 165 | { 166 | get 167 | { 168 | return string.Format(" {0} {1} ", OrderByField, OrderByType.ToString()); 169 | } 170 | } 171 | /// 172 | /// 排序字符返转 173 | /// 174 | public string OrderByStringReverse 175 | { 176 | get 177 | { 178 | return string.Format(" {0} {1} ", OrderByField, OrderByTypeReverse.ToString()); 179 | } 180 | } 181 | /// 182 | /// 排序字符返转 183 | /// 184 | public OrderByType OrderByTypeReverse 185 | { 186 | get 187 | { 188 | return IsAsc ? OrderByType.Desc : OrderByType.Asc; 189 | } 190 | } 191 | /// 192 | /// 是升序 193 | /// 194 | public bool IsAsc 195 | { 196 | get 197 | { 198 | return OrderByType == OrderByType.Asc; 199 | } 200 | } 201 | /// 202 | /// 比较符 203 | /// 204 | public string Symbol 205 | { 206 | get 207 | { 208 | return IsAsc ? "<" : ">"; 209 | } 210 | } 211 | /// 212 | /// 比较符反转 213 | /// 214 | public string SymbolReverse 215 | { 216 | get 217 | { 218 | return IsAsc ? ">" : "<"; 219 | } 220 | } 221 | } 222 | } 223 | -------------------------------------------------------------------------------- /SqlSugar/Cloud/CloudPubMethod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SQLiteSugar 8 | { 9 | 10 | internal class CloudPubMethod 11 | { 12 | public static Random random = new Random(); 13 | 14 | /// 15 | /// 获取pageIndex 16 | /// 17 | /// 18 | /// 19 | public static int GetPageIndex(int pageIndex, double configCount) 20 | { 21 | var index = pageIndex / configCount; 22 | if (index <= 1) 23 | { 24 | index = 1; 25 | } 26 | else if (pageIndex % configCount != 0) 27 | { 28 | index = (int)index + 1; 29 | } 30 | return (int)index; 31 | } 32 | 33 | /// 34 | /// 根据rate获取随机Connection 35 | /// 36 | /// 37 | public static string GetConnection(List configList) 38 | { 39 | Check.Exception(configList == null || configList.Count == 0, "CloudPubMethod.GetConnection.configList不能为null并且count>0。"); 40 | List connectionNameList = new List(); 41 | SetConnectionNameList(configList, ref connectionNameList); 42 | var index = random.Next(0, connectionNameList.Count); 43 | return connectionNameList[index]; 44 | } 45 | 46 | /// 47 | /// 并行执行任务并且传入索引 48 | /// 49 | /// 函数参数i 50 | /// task数组 51 | /// 索引 52 | public static void TaskFactory(Func method, Task[] tasks, int i) 53 | { 54 | tasks[i] = Task.Factory.StartNew(() => 55 | { 56 | return method(i); 57 | }); ; 58 | } 59 | 60 | 61 | private static void SetConnectionNameList(List configList, ref List connectionNameList) 62 | { 63 | var cacheKey = "SetConnectionNameList"; 64 | var cm = CacheManager>.GetInstance(); 65 | if (cm.ContainsKey(cacheKey)) 66 | { 67 | connectionNameList = cm[cacheKey]; 68 | } 69 | else 70 | { 71 | foreach (CloudConnectionConfig config in configList) 72 | { 73 | for (int i = 0; i < config.Rate; i++) 74 | { 75 | connectionNameList.Add(config.ConnectionString); 76 | } 77 | } 78 | cm.Add(cacheKey, connectionNameList, cm.Day); 79 | } 80 | } 81 | /// 82 | /// 分页索引是否很小 83 | /// 84 | /// 85 | /// 86 | /// 87 | /// 88 | /// 89 | public static bool GetIsSmallPageIndex(int pageIndex, int pageSize, int configCount, int maxHandleNumber) 90 | { 91 | if (pageIndex <= configCount) 92 | { 93 | return pageIndex * pageSize * configCount <= maxHandleNumber; 94 | 95 | } 96 | return false; 97 | } 98 | /// 99 | /// 倒数分页索引是否很小 100 | /// 101 | /// 102 | /// 103 | /// 104 | /// 105 | /// 106 | /// 107 | public static bool GetIsSmallPageIndexByReverse(int totalPage, int pageIndex, int pageSize, int configCount, int maxHandleNumber) 108 | { 109 | //倒数第几页 110 | var lastPage=(totalPage - pageIndex)+1 ; 111 | if (lastPage <= configCount) 112 | { 113 | return lastPage * pageSize <= maxHandleNumber; 114 | } 115 | return false; 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /SqlSugar/Cloud/TaskExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Data; 7 | namespace SQLiteSugar 8 | { 9 | /// 10 | /// Taskable扩展类 11 | /// 12 | public static class TaskExtensions 13 | { 14 | /// 15 | /// 获取count 16 | /// 17 | /// 18 | /// 19 | public static int Count(this Taskable thisValue) 20 | { 21 | return thisValue.Tasks.Select(it => it.Result.Value).Sum(); 22 | } 23 | 24 | /// 25 | ///是否存在这条记录 26 | /// 27 | /// 28 | /// 29 | public static bool Any(this Taskable thisValue) 30 | { 31 | return thisValue.Tasks.Select(it => it.Result.Value).Count() > 0; 32 | } 33 | 34 | /// 35 | /// 获取最大值 36 | /// 37 | /// 38 | /// 39 | /// 40 | public static T Max(this Taskable thisValue) 41 | { 42 | var isClass = typeof(T).IsClass; 43 | if (isClass) 44 | { 45 | Check.Exception(isClass, "TaskExtensions.Max.thisValue T只能是为string和值类型。"); 46 | } 47 | return thisValue.Tasks.Select(it => it.Result.Value).Max(); 48 | } 49 | 50 | /// 51 | /// 获取平均值 52 | /// 53 | /// 54 | /// 55 | public static int Avg(this TaskableWithCount thisValue) 56 | { 57 | var count = thisValue.Tasks.Select(it => it.Result.Count).Sum(); 58 | if (count == 0) return 0; 59 | var reval = thisValue.Tasks.Select(it => it.Result.Value * it.Result.Count).Sum() / count; 60 | return reval; 61 | } 62 | /// 63 | /// 获取平均值 64 | /// 65 | /// 66 | /// 67 | public static decimal Avg(this TaskableWithCount thisValue) 68 | { 69 | var count = thisValue.Tasks.Select(it => it.Result.Count).Sum(); 70 | if (count == 0) return 0; 71 | var reval = thisValue.Tasks.Select(it => it.Result.Value * it.Result.Count).Sum() / count; 72 | return reval; 73 | } 74 | /// 75 | /// 获取平均值 76 | /// 77 | /// 78 | /// 79 | public static double Avg(this TaskableWithCount thisValue) 80 | { 81 | var count = thisValue.Tasks.Select(it => it.Result.Count).Sum(); 82 | if (count == 0) return 0; 83 | var reval = thisValue.Tasks.Select(it => it.Result.Value * it.Result.Count).Sum() / count; 84 | return reval; 85 | } 86 | 87 | 88 | /// 89 | /// 获取最小值 90 | /// 91 | /// 92 | /// 93 | /// 94 | public static T Min(this Taskable thisValue) 95 | { 96 | var isClass = typeof(T).IsClass; 97 | if (isClass) 98 | { 99 | Check.Exception(isClass, "TaskExtensions.Min.thisValue T只能是为string和值类型。"); 100 | } 101 | return thisValue.Tasks.Select(it => it.Result.Value).Min(); 102 | } 103 | 104 | 105 | /// 106 | /// 将Task中的结果集合并成List集成 107 | /// 108 | /// 109 | /// 110 | /// 111 | public static List ToList(this Taskable thisValue) where T : class 112 | { 113 | var isClass = typeof(T).IsClass; 114 | if (!isClass) 115 | { 116 | Check.Exception(isClass, "TaskExtensions.ToList.thisValue T只能为class。"); 117 | } 118 | return thisValue.MergeEntities(); 119 | } 120 | 121 | 122 | /// 123 | /// 返回序列中的唯一元素;如果该序列为空,此方法将引发异常;如果该序列包含多个元素,此方法将引发异常。 124 | /// 125 | /// 126 | /// 127 | /// 128 | public static T ToSingle(this Taskable thisValue) where T : class 129 | { 130 | var isClass = typeof(T).IsClass; 131 | if (!isClass) 132 | { 133 | Check.Exception(isClass, "TaskExtensions.ToSingle.thisValue T只能为class。"); 134 | } 135 | return thisValue.MergeEntities().Single(); 136 | } 137 | 138 | /// 139 | /// 返回序列中的唯一元素;如果该序列为空,则返回默认值;如果该序列包含多个元素,此方法将引发异常。 140 | /// 141 | /// 142 | /// 143 | /// 144 | public static T ToSingleOrDefault(this Taskable thisValue) where T : class 145 | { 146 | var isClass = typeof(T).IsClass; 147 | if (!isClass) 148 | { 149 | Check.Exception(isClass, "TaskExtensions.ToSingle.thisValue T只能为class。"); 150 | } 151 | return thisValue.MergeEntities().SingleOrDefault(); 152 | } 153 | 154 | 155 | /// 156 | /// 获取第一行数据,,如果序列中不包含任何元素,则会抛出异常 157 | /// 158 | /// 159 | /// 160 | /// 161 | public static T ToFirst(this Taskable thisValue) where T : class 162 | { 163 | var isClass = typeof(T).IsClass; 164 | if (!isClass) 165 | { 166 | Check.Exception(isClass, "TaskExtensions.ToSingle.thisValue T只能为class。"); 167 | } 168 | return thisValue.MergeEntities().First(); 169 | } 170 | 171 | /// 172 | /// 如果序列中不包含任何元素,则返回默认值。 173 | /// 174 | /// 175 | /// 176 | /// 177 | public static T ToFirstOrDefault(this Taskable thisValue) where T : class 178 | { 179 | var isClass = typeof(T).IsClass; 180 | if (!isClass) 181 | { 182 | Check.Exception(isClass, "TaskExtensions.ToSingle.thisValue T只能为class。"); 183 | } 184 | return thisValue.MergeEntities().FirstOrDefault(); 185 | } 186 | 187 | 188 | 189 | /// 190 | /// 将结果集合并到一个集合 191 | /// 192 | /// 193 | /// 194 | /// 195 | public static IEnumerable MergeTable(this Taskable thisValue) 196 | { 197 | 198 | var isDataTable = typeof(System.Data.DataTable) == typeof(DataTable); 199 | if (!isDataTable) 200 | { 201 | Check.Exception(isDataTable, "TaskExtensions.MergeTable.thisValue T只能为DataTable。"); 202 | } 203 | var reval = thisValue.Tasks.SelectMany(it => it.Result.DataTable.AsEnumerable()).ToList(); 204 | return reval; 205 | } 206 | 207 | /// 208 | /// 将结果集合并到一个集合 209 | /// 210 | /// 211 | /// 212 | /// 213 | public static List MergeEntities(this Taskable thisValue) where T : class 214 | { 215 | 216 | var reval = thisValue.Tasks.SelectMany(it => it.Result.Entities).ToList(); 217 | return reval; 218 | } 219 | 220 | 221 | /// 222 | /// 将结果集合并到一个集合 223 | /// 224 | /// 225 | /// 226 | /// 227 | public static List MergeValue(this Taskable thisValue) 228 | { 229 | 230 | var reval = thisValue.Tasks.Select(it => it.Result.Value).ToList(); 231 | return reval; 232 | } 233 | } 234 | 235 | } 236 | -------------------------------------------------------------------------------- /SqlSugar/Core/IDataRecordExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Data; 6 | 7 | namespace SQLiteSugar 8 | { 9 | /// 10 | /// ** 描述:IDataRecord扩展类 11 | /// ** 创始时间:2016-8-7 12 | /// ** 修改时间:- 13 | /// ** 作者:孙凯旋 14 | /// ** 使用说明: 15 | /// 16 | public static class IDataRecordExtensions 17 | { 18 | /// 19 | /// 获取bool 20 | /// 21 | /// 22 | /// 23 | /// 24 | public static bool? GetConvertBoolean(this IDataRecord dr, int i) 25 | { 26 | if (dr.IsDBNull(i)) 27 | { 28 | return null; 29 | } 30 | var reval = dr.GetBoolean(i); 31 | return reval; 32 | } 33 | 34 | /// 35 | /// 获取byte 36 | /// 37 | /// 38 | /// 39 | /// 40 | public static byte? GetConvertByte(this IDataRecord dr, int i) 41 | { 42 | if (dr.IsDBNull(i)) 43 | { 44 | return null; 45 | } 46 | var reval = dr.GetByte(i); 47 | return reval; 48 | } 49 | 50 | /// 51 | /// 获取char 52 | /// 53 | /// 54 | /// 55 | /// 56 | public static char? GetConvertChar(this IDataRecord dr, int i) 57 | { 58 | if (dr.IsDBNull(i)) 59 | { 60 | return null; 61 | } 62 | var reval = dr.GetChar(i); 63 | return reval; 64 | } 65 | 66 | /// 67 | /// 获取时间 68 | /// 69 | /// 70 | /// 71 | /// 72 | public static DateTime? GetConvertDateTime(this IDataRecord dr, int i) 73 | { 74 | if (dr.IsDBNull(i)) 75 | { 76 | return null; 77 | } 78 | var reval = dr.GetDateTime(i); 79 | return reval; 80 | } 81 | 82 | /// 83 | /// 获取转换Decimal 84 | /// 85 | /// 86 | /// 87 | /// 88 | public static decimal? GetConvertDecimal(this IDataRecord dr, int i) 89 | { 90 | if (dr.IsDBNull(i)) 91 | { 92 | return null; 93 | } 94 | var reval = dr.GetDecimal(i); 95 | return reval; 96 | } 97 | 98 | /// 99 | /// 获取Double 100 | /// 101 | /// 102 | /// 103 | /// 104 | public static double? GetConvertDouble(this IDataRecord dr, int i) 105 | { 106 | if (dr.IsDBNull(i)) 107 | { 108 | return null; 109 | } 110 | var reval = dr.GetDouble(i); 111 | return reval; 112 | } 113 | 114 | /// 115 | /// 获取GUID 116 | /// 117 | /// 118 | /// 119 | /// 120 | public static Guid? GetConvertGuid(this IDataRecord dr, int i) 121 | { 122 | if (dr.IsDBNull(i)) 123 | { 124 | return null; 125 | } 126 | var reval = dr.GetGuid(i); 127 | return reval; 128 | } 129 | 130 | /// 131 | /// 获取int16 132 | /// 133 | /// 134 | /// 135 | /// 136 | public static short? GetConvertInt16(this IDataRecord dr, int i) 137 | { 138 | if (dr.IsDBNull(i)) 139 | { 140 | return null; 141 | } 142 | var reval = dr.GetInt16(i); 143 | return reval; 144 | } 145 | 146 | /// 147 | /// 获取int32 148 | /// 149 | /// 150 | /// 151 | /// 152 | public static Int32? GetConvertInt32(this IDataRecord dr, int i) 153 | { 154 | if (dr.IsDBNull(i)) 155 | { 156 | return null; 157 | } 158 | var reval = dr.GetInt32(i); 159 | return reval; 160 | } 161 | 162 | /// 163 | /// 获取int64 164 | /// 165 | /// 166 | /// 167 | /// 168 | public static long? GetConvetInt64(this IDataRecord dr, int i) 169 | { 170 | if (dr.IsDBNull(i)) 171 | { 172 | return null; 173 | } 174 | var reval = dr.GetInt64(i); 175 | return reval; 176 | } 177 | 178 | /// 179 | /// 获取float 180 | /// 181 | /// 182 | /// 183 | /// 184 | public static float? GetConvertFloat(this IDataRecord dr, int i) 185 | { 186 | if (dr.IsDBNull(i)) 187 | { 188 | return null; 189 | } 190 | var reval = dr.GetFloat(i); 191 | return reval; 192 | } 193 | 194 | /// 195 | /// 获取其它类型 196 | /// 197 | /// 198 | /// 199 | /// 200 | /// 201 | public static Nullable GetOtherNull(this IDataReader dr, int i) where T : struct 202 | { 203 | if (dr.IsDBNull(i)) 204 | { 205 | return null; 206 | } 207 | return (T)Convert.ChangeType(dr.GetValue(i), typeof(T)); 208 | 209 | } 210 | 211 | /// 212 | /// 获取其它类型 213 | /// 214 | /// 215 | /// 216 | /// 217 | /// 218 | public static T GetOther(this IDataReader dr, int i) 219 | { 220 | return (T)Convert.ChangeType(dr.GetValue(i), typeof(T)); 221 | } 222 | 223 | /// 224 | /// 获取枚举 225 | /// 226 | /// 227 | /// 228 | /// 229 | /// 230 | public static Nullable GetConvertEnum_Nullable(this IDataReader dr, int i) where T : struct 231 | { 232 | if (dr.IsDBNull(i)) 233 | { 234 | return null; 235 | } 236 | object value = dr.GetValue(i); 237 | T t = (T)Enum.ToObject(typeof(T), value); 238 | return t; 239 | } 240 | 241 | } 242 | } 243 | -------------------------------------------------------------------------------- /SqlSugar/Core/ResolveExpress/Constant.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLiteSugar 7 | { 8 | //局部类:拉姆达解析公用常量 9 | internal partial class ResolveExpress 10 | { 11 | /// 12 | /// 解析bool类型用到的字典 13 | /// 14 | public static List ConstantBoolDictionary = new List() 15 | { 16 | new ExpressBoolModel(){ Key=Guid.NewGuid(), OldValue="True", Type=SqlSugarTool.StringType}, 17 | new ExpressBoolModel(){ Key=Guid.NewGuid(), OldValue="False",Type=SqlSugarTool.StringType}, 18 | new ExpressBoolModel(){ Key=Guid.NewGuid(), OldValue="True",Type=SqlSugarTool.BoolType}, 19 | new ExpressBoolModel(){ Key=Guid.NewGuid(), OldValue="False",Type=SqlSugarTool.BoolType} 20 | 21 | }; 22 | /// 23 | /// 字段名解析错误 24 | /// 25 | public const string FileldErrorMessage = "OrderBy、GroupBy、In、Min和Max等操作不是有效拉姆达格式 ,正确格式 it=>it.name "; 26 | /// 27 | /// 拉姆达解析错误 28 | /// 29 | public const string ExpToSqlError= @"拉姆达解析出错,不是有效的函数,找不到合适函数你可以使用这种字符串写法.Where(""date>dateadd(@date)"",new{date=DateTime.Now}), 30 | 支持的函数有(请复制到本地查看,数量比较多): 31 | db.Queryable().Where(it => it.field == parValue.ObjToString()); 32 | db.Queryable().Where(it => it.field == parValue.ObjToDate()); 33 | db.Queryable().Where(it => it.field == parValue.ObjToInt()) 34 | db.Queryable().Where(it => it.field == parValue.ObjToDecimal()) 35 | db.Queryable().Where(it => it.field == parValue.ObjToMoney()) 36 | db.Queryable().Where(it => it.field == parValue.Trim()) 37 | db.Queryable().Where(it => it.field == parValue.ToString()) 38 | db.Queryable().Where(it => it.field == Convert.ToXXX(parValue)) 39 | db.Queryable().Where(it => it.field.Contains(parValue)) 40 | db.Queryable().Where(it => it.field.StartsWith(parValue)) 41 | db.Queryable().Where(it => it.field.EndsWith(parValue)) 42 | db.Queryable().Where(it => !string.IsNullOrEmpty(it.parValue)) 43 | db.Queryable().Where(it => arrayOrList.Contains(it.parValue)) 44 | db.Queryable().Where(it => it.field.Equals(it.parValue)) 45 | db.Queryable().Where(it => it.field.Length>10) 46 | db.Queryable().Where(c => c.field == parValue.ToLower()).ToList(); 47 | db.Queryable().Where(c => c.field == parValue.ToUpper()).ToList(); 48 | "; 49 | /// 50 | /// 运算符错误 51 | /// 52 | public const string OperatorError = "拉姆达解析出错:不支持{0}此种运算符查找!"; 53 | 54 | /// 55 | /// 拉姆达解析唯一标识 56 | /// 57 | public static object ExpErrorUniqueKey = Guid.NewGuid(); 58 | 59 | /// 60 | /// 拉姆达函数错误 61 | /// 62 | public const string ExpMethodError = "拉姆达表达式中的函数用法不正确,正确写法 it=>it.name.{0}(参数) ,不支持的写法it=> 参数.{0}(it.name)。"; 63 | 64 | 65 | /// 66 | /// 拉姆达函数错误2 67 | /// 68 | public const string ExpMethodError2 = "拉姆达表达式中的函数用法不正确,正确写法 it=>it.name==参数.{0} ,不支持的写法it=>it.name.{0}==参数。"; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /SqlSugar/Core/ResolveExpress/Models.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLiteSugar 7 | { 8 | //局部类:解析用到的实体 9 | internal partial class ResolveExpress 10 | { 11 | /// 12 | /// 拉姆达成员类型 13 | /// 14 | public enum MemberType 15 | { 16 | None = 0, 17 | Key = 1, 18 | Value = 2 19 | } 20 | /// 21 | /// 用来处理bool类型的实体 22 | /// 23 | public class ExpressBoolModel 24 | { 25 | /// 26 | /// 唯一标识 27 | /// 28 | public Guid Key { get; set; } 29 | /// 30 | /// 数据类型 31 | /// 32 | public Type Type { get; set; } 33 | /// 34 | /// 原始值 35 | /// 36 | public string OldValue { get; set; } 37 | /// 38 | /// 处事后的值 39 | /// 40 | public string NewValue 41 | { 42 | get 43 | { 44 | if (Type == SqlSugarTool.BoolType) 45 | { 46 | return Convert.ToBoolean(OldValue) ? "1" : "0"; 47 | } 48 | else 49 | { 50 | return OldValue.ToString(); 51 | } 52 | } 53 | } 54 | /// 55 | /// 处理后的运算对象 56 | /// 57 | public string ConditionalValue 58 | { 59 | get 60 | { 61 | return Convert.ToBoolean(OldValue) ? "(1=1)" : "(1=2)"; 62 | } 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /SqlSugar/Core/ResolveExpress/Property.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLiteSugar 7 | { 8 | //局部类:解析属性 9 | internal partial class ResolveExpress 10 | { 11 | private string GetProMethod(string methodName, string value, bool isField) 12 | { 13 | switch (methodName) 14 | { 15 | case "Length": 16 | return ProLength(value, isField); 17 | default: throw new SqlSugarException("不支持属性扩展方法" + methodName + "。"); 18 | } 19 | } 20 | private string ProLength(string value, bool isField) 21 | { 22 | if (isField) 23 | { 24 | return string.Format("length({0})", value.GetTranslationSqlName()); 25 | } 26 | else 27 | { 28 | return string.Format("{0}", value.ObjToString().Length); 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /SqlSugar/Core/ResolveExpress/ResolveFieldName.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Linq.Expressions; 6 | 7 | namespace SQLiteSugar 8 | { 9 | //局部类 解析字段名 10 | internal partial class ResolveExpress 11 | { 12 | /// 13 | /// 获取拉姆达表达式的字段值 14 | /// 15 | /// 16 | /// 数据库访问对象 17 | /// 18 | public string GetExpressionRightField(Expression exp, SqlSugarClient db) 19 | { 20 | DB = db; 21 | string reval = ""; 22 | LambdaExpression lambda = exp as LambdaExpression; 23 | var isConvet = lambda.Body.NodeType.IsIn(ExpressionType.Convert); 24 | var isMember = lambda.Body.NodeType.IsIn(ExpressionType.MemberAccess); 25 | if (!isConvet && !isMember) 26 | { 27 | throw new SqlSugarException(FileldErrorMessage); 28 | } 29 | try 30 | { 31 | if (isConvet) 32 | { 33 | var memberExpr =((UnaryExpression)lambda.Body).Operand as MemberExpression; 34 | reval= memberExpr.Member.Name; 35 | } 36 | else//isMember 37 | { 38 | reval= (lambda.Body as MemberExpression).Member.Name; 39 | } 40 | } 41 | catch (Exception) 42 | { 43 | throw new SqlSugarException(FileldErrorMessage); 44 | } 45 | if (DB != null && DB.IsEnableAttributeMapping && DB._mappingColumns.IsValuable()) 46 | { 47 | if (DB._mappingColumns.Any(it => it.Key == reval)) 48 | { 49 | var dbName = DB._mappingColumns.Single(it => it.Key == reval).Value; 50 | return dbName; 51 | } 52 | } 53 | return reval; 54 | } 55 | 56 | /// 57 | /// 获取拉姆达表达式的字段值多个T模式 58 | /// 59 | /// 60 | /// 数据库访问对象 61 | /// 62 | public string GetExpressionRightFieldByNT(Expression exp, SqlSugarClient db) 63 | { 64 | DB = db; 65 | string reval = ""; 66 | LambdaExpression lambda = exp as LambdaExpression; 67 | var isConvet = lambda.Body.NodeType.IsIn(ExpressionType.Convert); 68 | var isMember = lambda.Body.NodeType.IsIn(ExpressionType.MemberAccess); 69 | if (!isConvet && !isMember) 70 | { 71 | throw new SqlSugarException(FileldErrorMessage); 72 | } 73 | try 74 | { 75 | if (isConvet) 76 | { 77 | var memberExpr = ((UnaryExpression)lambda.Body).Operand as MemberExpression; 78 | reval= memberExpr.ToString(); 79 | } 80 | else//isMember 81 | { 82 | reval= lambda.Body.ToString(); 83 | } 84 | } 85 | catch (Exception) 86 | { 87 | throw new SqlSugarException(FileldErrorMessage); 88 | } 89 | if (DB != null && DB.IsEnableAttributeMapping && DB._mappingColumns.IsValuable()) 90 | { 91 | if (DB._mappingColumns.Any(it => reval.EndsWith("."+it.Key))) 92 | { 93 | var preName = reval.Split('.').First(); 94 | var dbName = DB._mappingColumns.Single(it => reval.EndsWith("." + it.Key)).Value; 95 | return preName+"."+dbName; 96 | } 97 | } 98 | return reval; 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /SqlSugar/Core/ResolveExpress/ResolveSelect.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using System.Text; 4 | using System.Text.RegularExpressions; 5 | using System.Linq.Expressions; 6 | 7 | namespace SQLiteSugar 8 | { 9 | 10 | /// 11 | /// ** 描述:解析Queryable.Select函数的参数 12 | /// ** 创始时间:2016-9-21 13 | /// ** 修改时间:- 14 | /// ** 作者:sunkaixuan 15 | /// ** qq:610262374 16 | /// ** 使用说明: 17 | /// 18 | internal class ResolveSelect 19 | { 20 | /// 21 | /// 多表情况 22 | /// 23 | /// 实体类型 24 | /// 拉姆达字符串 25 | /// 查旬对象 26 | /// 27 | internal static void GetResult(string expStr, Queryable reval, Expression exp) 28 | { 29 | var isComplexAnalysis = IsComplexAnalysis(expStr); 30 | reval.SelectValue = Regex.Match(expStr, @"(?<=\{).*?(?=\})").Value; 31 | if (reval.SelectValue.IsNullOrEmpty()) 32 | { 33 | reval.SelectValue = Regex.Match(expStr, @"[a-z,A-Z]\W* =>.*?\((.+)\)").Groups[1].Value; 34 | } 35 | var hasOutPar = expStr.Contains(SqlSugarTool.ParSymbol); 36 | if (hasOutPar)//有 37 | { 38 | var ms = Regex.Matches(expStr, @"""(\" + SqlSugarTool.ParSymbol + @"[a-z,A-Z]+)?""\.ObjTo[a-z,A-Z]+?\(\)").Cast().ToList(); 39 | foreach (var m in ms) 40 | { 41 | reval.SelectValue = reval.SelectValue.Replace(m.Groups[0].Value, m.Groups[1].Value); 42 | } 43 | } 44 | if (reval.SelectValue.IsNullOrEmpty()) 45 | { 46 | throw new SqlSugarException("Select 解析失败 ", new { selectString = reval.SelectValue }); 47 | } 48 | reval.SelectValue = reval.SelectValue.Replace("\"", "'"); 49 | reval.SelectValue = reval.SelectValue.Replace("DateTime.Now", "datetime('now', 'localtime')"); 50 | reval.SelectValue = ConvertFuns(reval.SelectValue, false); 51 | if (reval.DB != null && reval.DB.IsEnableAttributeMapping && reval.DB._mappingColumns.IsValuable()) 52 | { 53 | foreach (var item in reval.DB._mappingColumns) 54 | { 55 | reval.SelectValue = Regex.Replace(reval.SelectValue,@"\."+item.Key,"."+item.Value); 56 | } 57 | } 58 | reval.SelectValue = ConvertSelectValue(reval.SelectValue); 59 | } 60 | internal static string ConvertSelectValue(string selectValue) { 61 | if (selectValue.IsNullOrEmpty()) return "*"; 62 | var array = selectValue.Split(','); 63 | selectValue = string.Join(",", array.Select(it => { 64 | if(it.IsNullOrEmpty())return it; 65 | if(!it.Contains("=")) return it; 66 | var innerArray=it.Split('=').OrderBy(a=>a.Split('.').Length).ToArray(); 67 | return innerArray.Last().GetTranslationSqlName().Trim() + " AS " + innerArray.First().Trim().GetTranslationSqlName(); 68 | })); 69 | return selectValue; 70 | } 71 | 72 | private static bool IsComplexAnalysis(string expStr) 73 | { 74 | string errorFunName = null; 75 | if (expStr.IsValuable() && (expStr.Contains("+<>") || Regex.IsMatch(expStr, @"\.[a-z,A-Z,_]\w*\.[a-z,A-Z,_]\w*?(\,|\})"))) 76 | { 77 | throw new SqlSugarException("Select中的拉姆达表达式,不支持外部传参数,目前支持的写法 Where(\"1=1\",new {id=1}).Select(it=>{ id=\"" + SqlSugarTool.ParSymbol + "id\".ObjToInt()}"); 78 | } 79 | if(expStr.IsValuable()&&Regex.IsMatch(expStr, @"\+|\-|\*|\/")){ 80 | throw new SqlSugarException("Select中不支持变量的运算。"); 81 | } 82 | string reg= @"(\.[a-z,A-Z,_]\w*?\(.*?\))|\=\s*[a-z,A-Z,_]\w*?\(.*?\)|\=\s*[a-z,A-Z,_]\w*?\(.*?\)|\=[a-z,A-Z,_]\w*.[a-z,A-Z,_]\w*.[a-z,A-Z,_]\w*"; 83 | if (expStr.IsValuable() & Regex.IsMatch(expStr,reg)) 84 | { 85 | var ms = Regex.Matches(expStr, reg); 86 | var errorNum = 0; 87 | foreach (Match item in ms.Cast().OrderBy(it=>it.Value.Split('.').Length)) 88 | { 89 | if (item.Value == null) { 90 | errorNum++; 91 | break; 92 | } 93 | if (!item.Value.IsMatch(@"\.ObjTo|Convert|ToString")) 94 | { 95 | errorNum++; 96 | errorFunName = item.Value; 97 | break; 98 | } 99 | } 100 | if (errorNum > 0) 101 | { 102 | throw new SqlSugarException("Select中不支持函数"+errorFunName); 103 | } 104 | } 105 | return false; 106 | } 107 | /// 108 | /// 单表情况 109 | /// 110 | /// 实体类型 111 | /// 查旬对象 112 | /// 113 | internal static void GetResult(Queryable reval, Expression exp) 114 | { 115 | string expStr = reval.SelectValue; 116 | var isComplexAnalysis = IsComplexAnalysis(expStr); 117 | expStr = Regex.Match(expStr, @"(?<=\{).*?(?=\})").Value; 118 | if (expStr.IsNullOrEmpty()) 119 | { 120 | expStr = Regex.Match(reval.SelectValue, @"[a-z,A-Z]\W* =>.*?\((.+)\)").Groups[1].Value; 121 | } 122 | var hasOutPar = expStr.Contains(SqlSugarTool.ParSymbol); 123 | if (hasOutPar)//有 124 | { 125 | var ms = Regex.Matches(expStr, @"""(\" + SqlSugarTool.ParSymbol + @"[a-z,A-Z]+)?""\.ObjTo[a-z,A-Z]+?\(\)").Cast().ToList(); 126 | foreach (var m in ms) 127 | { 128 | expStr = expStr.Replace(m.Groups[0].Value, m.Groups[1].Value); 129 | } 130 | } 131 | expStr = Regex.Replace(expStr, @"(?<=\=)[^\,]*?\.", ""); 132 | if (reval.SelectValue.IsNullOrEmpty()) 133 | { 134 | throw new SqlSugarException("Select 解析失败 ", new { selectString = reval.SelectValue }); 135 | } 136 | expStr = expStr.Replace("\"", "'"); 137 | expStr = expStr.Replace("DateTime.Now", " datetime('now', 'localtime')"); 138 | expStr = ConvertFuns(expStr); 139 | reval.SelectValue = expStr; 140 | if (reval.DB != null && reval.DB.IsEnableAttributeMapping && reval.DB._mappingColumns.IsValuable()) 141 | { 142 | foreach (var item in reval.DB._mappingColumns) 143 | { 144 | reval.SelectValue = Regex.Replace(reval.SelectValue, @"\=" + item.Key, "=" + item.Value); 145 | } 146 | } 147 | reval.SelectValue = ConvertSelectValue(reval.SelectValue); 148 | } 149 | 150 | /// 151 | /// 替换函数 152 | /// 153 | /// 拉姆达字符串 154 | /// true为单表,false为多表 155 | /// 156 | internal static string ConvertFuns(string selectStr, bool isOneT = true) 157 | { 158 | if (isOneT == false)//多表 159 | { 160 | var hasFun = selectStr.Contains(")"); 161 | if (hasFun) 162 | { 163 | var m1 = Regex.Matches(selectStr, @"To[A-Z][a-z]+?\(Convert\((.+?)\)\)").Cast().ToList(); 164 | if (m1.IsValuable()) 165 | { 166 | foreach (var m in m1) 167 | { 168 | selectStr = selectStr.Replace(m.Groups[0].Value, m.Groups[1].Value); 169 | } 170 | } 171 | var m2 = Regex.Matches(selectStr, @"Convert\((.+?)\)\.ObjTo[a-z,A-Z]+?\(\)").Cast().ToList(); 172 | if (m2.IsValuable()) 173 | { 174 | foreach (var m in m2) 175 | { 176 | selectStr = selectStr.Replace(m.Groups[0].Value, m.Groups[1].Value); 177 | } 178 | } 179 | var m3 = Regex.Matches(selectStr, @"Convert\((.+?)\)").Cast().ToList(); 180 | if (m3.IsValuable()) 181 | { 182 | foreach (var m in m3) 183 | { 184 | selectStr = selectStr.Replace(m.Groups[0].Value, m.Groups[1].Value); 185 | } 186 | } 187 | } 188 | 189 | } 190 | else//单表 191 | { 192 | var hasObjToFun = Regex.IsMatch(selectStr, @"\)\s*\.ObjTo[a-z,A-Z]+?\(\s*\)"); 193 | if (hasObjToFun) 194 | { 195 | selectStr = Regex.Replace(selectStr, @"\)\s*\.ObjTo[a-z,A-Z]+?\(\s*\)", ""); 196 | } 197 | var hasFun = selectStr.Contains(")"); 198 | if (hasFun) 199 | { 200 | selectStr = selectStr.Replace(")", ""); 201 | selectStr = selectStr.Replace("(", ""); 202 | } 203 | } 204 | if (selectStr.Contains(".ToString")) 205 | { 206 | throw new SqlSugarException("Select中不支持ToString函数,请使用ObjectToString"); 207 | } 208 | if (selectStr.Contains("+<>")) 209 | { 210 | throw new SqlSugarException("Select中的拉姆达表达式,不支持外部传参数,目前支持的写法 Where(\"1=1\",new {id=1}).Select(it=>{ id=\"" + SqlSugarTool.ParSymbol + "id\".ObjToInt()}"); 211 | } 212 | return selectStr; 213 | } 214 | } 215 | } 216 | -------------------------------------------------------------------------------- /SqlSugar/Generating/ClassTemplate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLiteSugar 7 | { 8 | 9 | /// 10 | /// 生成实体格式模版 11 | /// 12 | public class ClassTemplate 13 | { 14 | /// 15 | ///替换模版 16 | /// 17 | /// 18 | /// 19 | /// 20 | /// 21 | /// 22 | /// 23 | internal static string Replace(string templateStr, string nameSpaceStr, string foreachStr, string classNameStr, List primaryKeyName = null) 24 | { 25 | if (nameSpaceStr.IsNullOrEmpty()) 26 | { 27 | nameSpaceStr = "System"; 28 | } 29 | templateStr = templateStr.Replace("$foreach", foreachStr) 30 | .Replace("$namespace", nameSpaceStr) 31 | .Replace("$className", classNameStr); 32 | //处理主键 33 | if (primaryKeyName != null && primaryKeyName.Count > 0) 34 | { 35 | templateStr = templateStr.Replace("$primaryKeyName", primaryKeyName[0]); 36 | //处理特殊的主键取值 37 | for (int i = 0; i < primaryKeyName.Count; i++) 38 | { 39 | templateStr = templateStr.Replace("$primaryKeyName_" + i + "", primaryKeyName[i]); 40 | } 41 | } 42 | return templateStr; 43 | } 44 | 45 | /// 46 | /// 字段模版 47 | /// 48 | public static string ItemTemplate = " public {0}{3} {1} {2}"; 49 | 50 | /// 51 | /// 生成的实体类模版 52 | /// 53 | public static string Template = 54 | @"using System; 55 | using System.Linq; 56 | using System.Text; 57 | 58 | namespace $namespace 59 | { 60 | public class $className 61 | { 62 | $foreach 63 | } 64 | } 65 | "; 66 | /// 67 | /// 生成实体类字段摘要模版 68 | /// 69 | public static string ClassFieldSummaryTemplate = @" /// 70 | /// Desc:{0} 71 | /// Default:{1} 72 | /// Nullable:{2} 73 | /// 74 | "; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /SqlSugar/Generating/SugarAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Reflection; 6 | 7 | namespace SQLiteSugar 8 | { 9 | /// 10 | /// 表名属性 11 | /// 12 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Class, Inherited = true)] 13 | public class SugarMappingAttribute : Attribute 14 | { 15 | private string tableName; 16 | /// 17 | /// 据库对应的表名 18 | /// 19 | public string TableName 20 | { 21 | get { return tableName; } 22 | set { tableName = value; } 23 | } 24 | 25 | private string columnName; 26 | /// 27 | /// 数据库对应的列名 28 | /// 29 | public string ColumnName 30 | { 31 | get { return columnName; } 32 | set { columnName = value; } 33 | } 34 | } 35 | 36 | internal class ReflectionSugarMapping 37 | { 38 | /// 39 | /// 通过反射取自定义属性 40 | /// 41 | /// 42 | public static SugarMappingModel GetMappingInfo() 43 | { 44 | Type objType = typeof(T); 45 | string cacheKey = "ReflectionSugarMapping.DisplaySelfAttribute" + objType.FullName; 46 | var cm = CacheManager.GetInstance(); 47 | if (cm.ContainsKey(cacheKey)) 48 | { 49 | return cm[cacheKey]; 50 | } 51 | else 52 | { 53 | SugarMappingModel reval = new SugarMappingModel(); 54 | string tableName = string.Empty; 55 | List columnInfoList = new List(); 56 | var oldName = objType.Name; 57 | //取属性上的自定义特性 58 | foreach (PropertyInfo propInfo in objType.GetProperties()) 59 | { 60 | object[] objAttrs = propInfo.GetCustomAttributes(typeof(SugarMappingAttribute), true); 61 | if (objAttrs.Length > 0) 62 | { 63 | if (objAttrs[0] is SugarMappingAttribute) 64 | { 65 | SugarMappingAttribute attr = objAttrs[0] as SugarMappingAttribute; 66 | if (attr != null) 67 | { 68 | columnInfoList.Add(new KeyValue() { Key = propInfo.Name, Value = attr.ColumnName }); //列名 69 | } 70 | } 71 | } 72 | } 73 | 74 | //取类上的自定义特性 75 | object[] objs = objType.GetCustomAttributes(typeof(SugarMappingAttribute), true); 76 | foreach (object obj in objs) 77 | { 78 | if (obj is SugarMappingAttribute) 79 | { 80 | SugarMappingAttribute attr = obj as SugarMappingAttribute; 81 | if (attr != null) 82 | { 83 | 84 | tableName = attr.TableName;//表名只有获取一次 85 | break; 86 | } 87 | } 88 | } 89 | if (string.IsNullOrEmpty(tableName)) 90 | { 91 | tableName = objType.Name; 92 | } 93 | reval.TableMaping = new KeyValue() { Key = oldName, Value = tableName }; 94 | reval.ColumnsMapping = columnInfoList; 95 | cm.Add(cacheKey,reval,cm.Day); 96 | return reval; 97 | } 98 | } 99 | } 100 | 101 | internal class SugarMappingModel 102 | { 103 | 104 | public KeyValue TableMaping { get; set; } 105 | public List ColumnsMapping { get; set; } 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /SqlSugar/Lib/System.Data.SQLite.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DotNetNext/SqliteSugar/475c16eedeff52864f3d5e78829e5f1b74f6535c/SqlSugar/Lib/System.Data.SQLite.dll -------------------------------------------------------------------------------- /SqlSugar/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DotNetNext/SqliteSugar/475c16eedeff52864f3d5e78829e5f1b74f6535c/SqlSugar/NuGet.exe -------------------------------------------------------------------------------- /SqlSugar/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过以下 6 | // 特性集控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("SqlSugar")] 9 | [assembly: AssemblyDescription("作者:孙凯旋,蓝灯软件架构师")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("上海蓝灯软件有限公司")] 12 | [assembly: AssemblyProduct("SqlSugar")] 13 | [assembly: AssemblyCopyright("Copyright © 上 海蓝灯软件有限公司 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, 19 | // 则将该类型上的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("59fd4b0d-8a69-476f-ad02-33a9e179a7c2")] 24 | 25 | // 程序集的版本信息由下面四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订号 31 | // 32 | // 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("3.5.2.7")] 36 | [assembly: AssemblyFileVersion("3.5.2.7")] 37 | -------------------------------------------------------------------------------- /SqlSugar/PubModel/KeyValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLiteSugar 7 | { 8 | /// 9 | /// 自定义键值类 key is string, value is string 10 | /// 11 | public class KeyValue 12 | { 13 | /// 14 | /// 键 15 | /// 16 | public string Key { get; set; } 17 | /// 18 | /// 值 19 | /// 20 | public string Value { get; set; } 21 | } 22 | /// 23 | /// 自定义键值类 key is string, value is object 24 | /// 25 | public class KeyValueObj 26 | { 27 | /// 28 | /// 键 29 | /// 30 | public string Key { get; set; } 31 | /// 32 | /// 值 33 | /// 34 | public object Value { get; set; } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /SqlSugar/PubModel/PubEnum.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLiteSugar 7 | { 8 | /// 9 | /// join类型 10 | /// 11 | public enum JoinType 12 | { 13 | /// 14 | /// 等值连接 15 | /// 16 | Inner = 0, 17 | /// 18 | /// 左外连 19 | /// 20 | Left = 1, 21 | /// 22 | /// 右外连 23 | /// 24 | Right = 2 25 | } 26 | /// 27 | /// Apply类型 28 | /// 29 | public enum ApplyType 30 | { 31 | /// 32 | /// 笛卡尔积 33 | /// 34 | Cross = 1, 35 | /// 36 | /// 外连 37 | /// 38 | Outer = 2 39 | } 40 | /// 41 | /// 排序类型 42 | /// 43 | public enum OrderByType 44 | { 45 | /// 46 | /// 升序 47 | /// 48 | Asc = 0, 49 | /// 50 | /// 降序 51 | /// 52 | Desc = 1 53 | } 54 | /// 55 | /// 分页类型 56 | /// 57 | public enum PageModel 58 | { 59 | /// 60 | /// 05分页 61 | /// 62 | RowNumber = 0, 63 | 64 | } 65 | /// 66 | /// 解析类型 67 | /// 68 | public enum ResolveExpressType 69 | { 70 | /// 71 | /// 单个T 72 | /// 73 | OneT = 0, 74 | /// 75 | /// 多个T 76 | /// 77 | NT = 1, 78 | 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /SqlSugar/PubModel/PubModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLiteSugar 7 | { 8 | /// 9 | /// ** 描述:公共参数表 10 | /// ** 创始时间:2015-7-20 11 | /// ** 修改时间:- 12 | /// ** 作者:sunkaixuan 13 | /// ** 使用说明: 14 | /// 15 | public class PubModel 16 | { 17 | /// 18 | /// 用于存储数据表与列的映射信息 19 | /// 20 | public class DataTableMap 21 | { 22 | /// 23 | /// 表名 24 | /// 25 | public object TABLE_NAME { get; set; } 26 | /// 27 | /// 表ID 28 | /// 29 | public object TABLE_ID { get; set; } 30 | /// 31 | /// 列名 32 | /// 33 | public object COLUMN_NAME { get; set; } 34 | /// 35 | /// 数据类型 36 | /// 37 | public object DATA_TYPE { get; set; } 38 | /// 39 | /// 字符最大长度 40 | /// 41 | public object CHARACTER_MAXIMUM_LENGTH { get; set; } 42 | /// 43 | /// 备注 44 | /// 45 | public object COLUMN_DESCRIPTION { get; set; } 46 | /// 47 | /// 默认值 48 | /// 49 | public object COLUMN_DEFAULT { get; set; } 50 | /// 51 | /// 是否允许为null 52 | /// 53 | public object IS_NULLABLE { get; set; } 54 | /// 55 | /// 是否是主键 56 | /// 57 | public object IS_PRIMARYKEY { get; set; } 58 | } 59 | 60 | /// 61 | /// 流水号设置实体 62 | /// 63 | public class SerialNumber 64 | { 65 | /// 66 | /// 表名 67 | /// 68 | public string TableName { get; set; } 69 | /// 70 | /// 字段名 71 | /// 72 | public string FieldName { get; set; } 73 | /// 74 | /// 获取流水号函数 75 | /// 76 | public Func GetNumFunc { get; set; } 77 | /// 78 | /// 获取流水号函数(解决事务中死锁BUG) 79 | /// 80 | public Func GetNumFuncWithDb { get; set; } 81 | } 82 | 83 | /// 84 | /// 多语言设置的参数表 85 | /// 86 | public class Language 87 | { 88 | /// 89 | /// 数据库里面的语言后缀 90 | /// 91 | public string Suffix { get; set; } 92 | /// 93 | /// 数据库语言的VALUE 94 | /// 95 | public int LanguageValue { get; set; } 96 | /// 97 | /// 需要全局替换的字符串Key(用于替换默认语言) 98 | /// 99 | public string ReplaceViewStringKey = "LanguageId=1"; 100 | /// 101 | /// 需要全局替换的字符串Value(用于替换默认语言) 102 | /// 103 | public string ReplaceViewStringValue = "LanguageId = {0}"; 104 | 105 | } 106 | /// 107 | /// SqlSugarClient通用常量 108 | /// 109 | internal class SqlSugarClientConst { 110 | /// 111 | /// 属性设置错误信息 112 | /// 113 | public const string AttrMappingError = @"[SugarMapping(ColumnName = ""{1}"")] 114 | public string {0} {{ get; set; }}已经在其存在于其它表, Columns映射只能在 {0}->{1}和{0}->{2}二者选其一"; 115 | /// 116 | /// SqlQuery查询的SQL模板 117 | /// 118 | public const string SqlQuerySqlTemplate = @"-- {0} 119 | {1}"; 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /SqlSugar/Queryable/Queryable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Data.SQLite; 6 | using System.Linq.Expressions; 7 | 8 | namespace SQLiteSugar 9 | { 10 | 11 | /// 12 | /// ** 描述:Queryable拉姆达查询对象 13 | /// ** 创始时间:2015-7-13 14 | /// ** 修改时间:- 15 | /// ** 作者:sunkaixuan 16 | /// ** 使用说明: 17 | /// 18 | public class Queryable 19 | { 20 | #region 临时变量 21 | /// 22 | /// T的名称 23 | /// 24 | internal string TName { get { return typeof(T).Name; } } 25 | /// 26 | /// 实体类型 27 | /// 28 | internal Type Type { get { return typeof(T); } } 29 | /// 30 | /// 数据接口 31 | /// 32 | public SqlSugarClient DB = null; 33 | /// 34 | /// Where临时数据 35 | /// 36 | internal List WhereValue = new List(); 37 | /// 38 | /// Skip临时数据 39 | /// 40 | internal int? Skip { get; set; } 41 | /// 42 | /// Take临时数据 43 | /// 44 | internal int? Take { get; set; } 45 | /// 46 | /// Order临时数据 47 | /// 48 | internal string OrderByValue { get; set; } 49 | /// 50 | /// Select临时数据 51 | /// 52 | internal string SelectValue { get; set; } 53 | /// 54 | /// SqlParameter临时数据 55 | /// 56 | internal List Params = new List(); 57 | /// 58 | /// 表名临时数据 59 | /// 60 | internal string TableName { get; set; } 61 | /// 62 | /// 分组查询临时数据 63 | /// 64 | internal string GroupByValue { get; set; } 65 | /// 66 | /// 条件索引临时数据 67 | /// 68 | internal int WhereIndex = 1; 69 | /// 70 | /// 联表查询临时数据 71 | /// 72 | internal List JoinTableValue = new List(); 73 | 74 | #endregion 75 | 76 | 77 | #region 公开函数 78 | /// 79 | /// 联表查询 80 | /// 81 | /// 联接的表对象 82 | /// 表达式 83 | /// Join的类型 84 | /// 85 | public Queryable JoinTable(Expression> expression, JoinType type = JoinType.Left) 86 | { 87 | return this.JoinTable(expression, type); 88 | } 89 | 90 | /// 91 | /// 联表查询 92 | /// 93 | /// 联接表的对象 94 | /// 联接表的对象 95 | /// 表达式 96 | /// Join的类型 97 | /// 98 | public Queryable JoinTable(Expression> expression, JoinType type = JoinType.Left) 99 | { 100 | return this.JoinTable(expression, type); 101 | } 102 | 103 | /// 104 | /// 条件筛选 105 | /// 106 | /// 表实体类型 107 | /// 表达式条件 108 | /// 109 | public Queryable Where(Expression> expression) 110 | { 111 | return this.Where(expression); 112 | } 113 | /// 114 | /// 条件筛选 115 | /// 116 | /// 表实体类型 117 | /// Where后面的Sql条件语句 (例如: id=@id ) 118 | /// 匿名参数 (例如:new{id=1,name="张三"}) 119 | /// 120 | public Queryable Where(string whereString, object whereObj = null) 121 | { 122 | return this.Where(whereString, whereObj); 123 | } 124 | 125 | /// 126 | /// 条件筛选 127 | /// 128 | /// 表实体类型 129 | /// 表实体类型 130 | /// 表达式条件 131 | /// 132 | public Queryable Where(Expression> expression) 133 | { 134 | return this.Where(expression); 135 | } 136 | 137 | /// 138 | /// 条件筛选 139 | /// 140 | /// 表实体类型 141 | /// 表实体类型 142 | /// 表实体类型 143 | /// 表达式条件 144 | /// 145 | public Queryable Where(Expression> expression) 146 | { 147 | return this.Where(expression); 148 | } 149 | 150 | /// 151 | /// 条件筛选 152 | /// 153 | /// 表实体类型 154 | /// 表实体类型 155 | /// 表实体类型 156 | /// 表实体类型 157 | /// 表达式条件 158 | /// 159 | public Queryable Where(Expression> expression) 160 | { 161 | return this.Where(expression); 162 | } 163 | 164 | /// 165 | /// 排序 166 | /// 167 | /// 表实体类型 168 | /// 例如 (s1,s2)=>s1.id,相当于 order by s1.id 169 | /// 排序类型 170 | /// 171 | public Queryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) 172 | { 173 | return this.OrderBy(expression, type); 174 | } 175 | 176 | /// 177 | /// 获取最大值 178 | /// 179 | /// 返回类型 180 | /// 列名 181 | /// 182 | public TResult Max(string maxField) 183 | { 184 | return this.Max(maxField); 185 | } 186 | 187 | /// 188 | /// 获取最小值 189 | /// 190 | /// 返回类型 191 | /// 列名 192 | /// 193 | public TResult Min(string minField) 194 | { 195 | return this.Min(minField); 196 | } 197 | 198 | /// 199 | /// 将源数据对象转换到新对象中 200 | /// 201 | /// 原数据实体类型 202 | /// 返回值的新实体类型 203 | /// 给新实体赋值的表达式 204 | /// 205 | public Queryable Select(Expression> expression) 206 | { 207 | return this.Select(expression); 208 | } 209 | 210 | /// 211 | /// 将源数据对象转换到新对象中 212 | /// 213 | /// 原数据实体类型 214 | /// 原数据实体类型 215 | /// 返回值的新实体类型 216 | /// 给新实体赋值的表达式 217 | /// 218 | public Queryable Select(Expression> expression) 219 | { 220 | return this.Select(expression); 221 | } 222 | 223 | /// 224 | /// 将源数据对象转换到新对象中 225 | /// 226 | /// 原数据实体类型 227 | /// 原数据实体类型 228 | /// 原数据实体类型 229 | /// 返回值的新实体类型 230 | /// 给新实体赋值的表达式 231 | /// 232 | public Queryable Select(Expression> expression) 233 | { 234 | return this.Select(expression); 235 | } 236 | 237 | /// 238 | /// 将源数据对象转换到新对象中 239 | /// 240 | /// 原数据实体类型 241 | /// 原数据实体类型 242 | /// 原数据实体类型 243 | /// 原数据实体类型 244 | /// 返回值的新实体类型 245 | /// 给新实体赋值的表达式 246 | /// 247 | public Queryable Select(Expression> expression) 248 | { 249 | return this.Select(expression); 250 | } 251 | 252 | /// 253 | /// 将源数据对象转换到新对象中 254 | /// 255 | /// 返回值的新实体类型 256 | /// 给新实体赋值的表达式 257 | /// 258 | public Queryable Select(Expression> expression) 259 | { 260 | return this.Select(expression); 261 | } 262 | 263 | /// 264 | /// 将源数据对象转换到新对象中 265 | /// 266 | /// 返回值的新实体类型 267 | /// 查询字符串(例如 id,name) 268 | /// 269 | public Queryable Select(string select) 270 | { 271 | return this.Select(select); 272 | } 273 | #endregion 274 | 275 | 276 | } 277 | } 278 | -------------------------------------------------------------------------------- /SqlSugar/Sqlable/Sqlable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Data.SQLite; 6 | 7 | namespace SQLiteSugar 8 | { 9 | /// 10 | /// ** 描述:Queryable是多表查询基类,基于拥有大量查询扩展函数 11 | /// ** 创始时间:2015-7-13 12 | /// ** 修改时间:- 13 | /// ** 作者:sunkaixuan 14 | /// ** 使用说明: 15 | /// 16 | public class Sqlable 17 | { 18 | /// 19 | /// 数据接口 20 | /// 21 | public SqlSugarClient DB = null; 22 | /// 23 | /// sql临时数据 24 | /// 25 | public StringBuilder Sql { get; set; } 26 | /// 27 | /// Where临时数据 28 | /// 29 | public List Where = new List(); 30 | /// 31 | /// OrderBy临时数据 32 | /// 33 | public string OrderBy { get; set; } 34 | /// 35 | /// GroupBy临时数据 36 | /// 37 | public string GroupBy { get; set; } 38 | /// 39 | /// 参数 40 | /// 41 | public List Params = new List(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /SqlSugar/SqliteSugar.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {46A17E67-7E3E-4369-9B1F-43BA34BBDAEF} 9 | Library 10 | Properties 11 | SqliteSugar 12 | SqliteSugar 13 | v4.0 14 | 512 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | bin\Debug\SqliteSugar.XML 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | bin\Release\SqliteSugar.xml 34 | 35 | 36 | 37 | 38 | 39 | 40 | False 41 | Lib\System.Data.SQLite.dll 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 109 | -------------------------------------------------------------------------------- /SqlSugar/SqliteSugar.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | sqliteSugar 5 | 3.5.2.7 6 | SqliteSugar ORM 7 | sun kaixuan 8 | landa 9 | http://www.apache.org/licenses/LICENSE-2.0.html 10 | https://github.com/sunkaixuan/SqliteSugar 11 | https://secure.gravatar.com/avatar/a82c03402497b2e58fd65038a3699b30 12 | false 13 | SqlSugar ORM .NET 4.0+ High-performance, lightweight http://www.cnblogs.com/sunkaixuan/p/5654695.html 14 | Copyright 2015 15 | asp.net orm 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /SqlSugar/Tool/CacheManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Collections; 6 | using System.Linq.Expressions; 7 | 8 | namespace SQLiteSugar 9 | { 10 | /// 11 | /// ** 描述:缓存操作类 12 | /// ** 创始时间:2015-6-9 13 | /// ** 修改时间:- 14 | /// ** 作者:sunkaixuan 15 | /// ** 使用说明:http://www.cnblogs.com/sunkaixuan/p/4563462.html 16 | /// 17 | /// 值类型 18 | internal class CacheManager : IStorageObject 19 | { 20 | 21 | readonly System.Collections.Concurrent.ConcurrentDictionary InstanceCache = new System.Collections.Concurrent.ConcurrentDictionary(); 22 | 23 | #region 全局变量 24 | private static CacheManager _instance = null; 25 | private static readonly object _instanceLock = new object(); 26 | #endregion 27 | 28 | #region 构造函数 29 | 30 | private CacheManager() { } 31 | #endregion 32 | 33 | #region 属性 34 | /// 35 | ///根据key获取value 36 | /// 37 | /// 38 | public override V this[string key] 39 | { 40 | get 41 | { 42 | return this.Get(key); 43 | } 44 | } 45 | #endregion 46 | 47 | #region 公共函数 48 | 49 | /// 50 | /// 验证key是否存在 51 | /// 52 | /// key 53 | /// /// 存在true 不存在false. /// /// 54 | public override bool ContainsKey(string key) 55 | { 56 | return this.InstanceCache.ContainsKey(key); 57 | 58 | //throw new NotImplementedException(); 59 | //return HttpRuntime.Cache[CreateKey(key)] != null; 60 | } 61 | 62 | /// 63 | /// 根据key获取value 64 | /// 65 | /// key 66 | /// 67 | public override V Get(string key) 68 | { 69 | if (this.ContainsKey(key)) 70 | return this.InstanceCache[key]; 71 | else 72 | return default(V); 73 | } 74 | 75 | /// 76 | /// 获取实例 (单例模式) 77 | /// 78 | /// 79 | public static CacheManager GetInstance() 80 | { 81 | if (_instance == null) 82 | lock (_instanceLock) 83 | if (_instance == null) 84 | _instance = new CacheManager(); 85 | return _instance; 86 | } 87 | 88 | /// 89 | /// 插入缓存(默认20分钟) 90 | /// 91 | /// key 92 | /// value 93 | public override void Add(string key, V value) 94 | { 95 | this.InstanceCache.GetOrAdd(key, value); 96 | } 97 | 98 | /// 99 | /// 插入缓存 100 | /// 101 | /// key 102 | /// value 103 | /// 过期时间单位秒 104 | public void Add(string key, V value, int cacheDurationInSeconds) 105 | { 106 | Add(key, value); 107 | } 108 | 109 | ///// 110 | ///// 插入缓存. 111 | ///// 112 | ///// key 113 | ///// value 114 | ///// 过期时间单位秒 115 | ///// 缓存项属性 116 | //public void Add(string key, V value, int cacheDurationInSeconds, CacheItemPriority priority) 117 | //{ 118 | // string keyString = CreateKey(key); 119 | // HttpRuntime.Cache.Insert(keyString, value, null, DateTime.Now.AddSeconds(cacheDurationInSeconds), Cache.NoSlidingExpiration, priority, null); 120 | //} 121 | 122 | ///// 123 | ///// 插入缓存. 124 | ///// 125 | ///// key 126 | ///// value 127 | ///// 过期时间单位秒 128 | ///// 缓存项属性 129 | //public void Add(string key, V value, int cacheDurationInSeconds, CacheDependency dependency, CacheItemPriority priority) 130 | //{ 131 | // //string keyString = CreateKey(key); 132 | // //HttpRuntime.Cache.Insert(keyString, value, dependency, DateTime.Now.AddSeconds(cacheDurationInSeconds), Cache.NoSlidingExpiration, priority, null); 133 | //} 134 | 135 | /// 136 | /// 删除缓存 137 | /// 138 | /// key 139 | public override void Remove(string key) 140 | { 141 | V val; 142 | this.InstanceCache.TryRemove(key, out val); 143 | 144 | //throw new NotImplementedException(); 145 | //HttpRuntime.Cache.Remove(CreateKey(key)); 146 | } 147 | 148 | /// 149 | /// 清除所有缓存 150 | /// 151 | public override void RemoveAll() 152 | { 153 | this.InstanceCache.Clear(); 154 | 155 | } 156 | 157 | /// 158 | /// 清除所有缓存 159 | /// 160 | /// 表达式条件 161 | public override void RemoveAll(Func removeExpression) 162 | { 163 | //throw new NotImplementedException(); 164 | //System.Web.Caching.Cache _cache = HttpRuntime.Cache; 165 | var allKeyList = GetAllKey(); 166 | var delKeyList = allKeyList.Where(removeExpression).ToList(); 167 | foreach (var key in delKeyList) 168 | { 169 | Remove(key); 170 | } 171 | } 172 | 173 | /// 174 | /// 获取所有缓存key 175 | /// 176 | /// 177 | public override IEnumerable GetAllKey() 178 | { 179 | return this.InstanceCache.Keys; 180 | 181 | //throw new NotImplementedException(); 182 | //IDictionaryEnumerator CacheEnum = HttpRuntime.Cache.GetEnumerator(); 183 | //while (CacheEnum.MoveNext()) 184 | //{ 185 | // yield return CacheEnum.Key.ToString(); 186 | //} 187 | } 188 | #endregion 189 | 190 | 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /SqlSugar/Tool/Check.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLiteSugar 7 | { 8 | /// 9 | /// ** 描述:验证失败,则抛出异常 10 | /// ** 创始时间:2015-7-19 11 | /// ** 修改时间:- 12 | /// ** 作者:sunkaixuan 13 | /// ** 修改人:sunkaixuan 14 | /// ** 使用说明: 15 | /// 16 | public class Check 17 | { 18 | /// 19 | /// 使用导致此异常的参数的名称初始化 System.ArgumentNullException 类的新实例。 20 | /// 21 | /// 22 | /// 23 | public static void ArgumentNullException(object checkObj, string message) 24 | { 25 | if (checkObj == null) 26 | throw new ArgumentNullException(message); 27 | } 28 | /// 29 | /// 使用指定的错误消息初始化 System.Exception 类的新实例。 30 | /// 31 | /// true则引发异常 32 | /// 错误信息 33 | /// 参数 34 | public static void Exception(bool isException, string message, params string[] args) 35 | { 36 | if (isException) 37 | throw new SqlSugarException(string.Format(message, args)); 38 | } 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /SqlSugar/Tool/IStorageObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace SQLiteSugar 3 | { 4 | /// 5 | /// ** 描述:存储对象接口 6 | /// ** 创始时间:2015-5-29 7 | /// ** 修改时间:- 8 | /// ** 作者:sunkaixuan 9 | /// 10 | internal abstract class IStorageObject 11 | { 12 | 13 | public int Minutes = 60; 14 | public int Hour = 60 * 60; 15 | public int Day = 60 * 60 * 24; 16 | public abstract void Add(string key, V value); 17 | public abstract bool ContainsKey(string key); 18 | public abstract V Get(string key); 19 | public abstract global::System.Collections.Generic.IEnumerable GetAllKey(); 20 | public abstract void Remove(string key); 21 | public abstract void RemoveAll(); 22 | public abstract void RemoveAll(Func removeExpression); 23 | public abstract V this[string key] { get; } 24 | } 25 | } -------------------------------------------------------------------------------- /SqlSugar/Tool/IsWhatExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.RegularExpressions; 6 | 7 | namespace SQLiteSugar 8 | { 9 | /// 10 | /// ** 描述:逻辑判段是什么? 11 | /// ** 创始时间:2015-5-29 12 | /// ** 修改时间:- 13 | /// ** 作者:sunkaixuan 14 | /// ** 使用说明:http://www.cnblogs.com/sunkaixuan/p/4539654.html 15 | /// 16 | internal static class IsWhatExtensions 17 | { 18 | /// 19 | /// 值在的范围? 20 | /// 21 | /// 22 | /// 大于等于begin 23 | /// 小于等于end 24 | /// 25 | public static bool IsInRange(this int thisValue, int begin, int end) 26 | { 27 | return thisValue >= begin && thisValue <= end; 28 | } 29 | /// 30 | /// 值在的范围? 31 | /// 32 | /// 33 | /// 大于等于begin 34 | /// 小于等于end 35 | /// 36 | public static bool IsInRange(this DateTime thisValue, DateTime begin, DateTime end) 37 | { 38 | return thisValue >= begin && thisValue <= end; 39 | } 40 | 41 | /// 42 | /// 在里面吗? 43 | /// 44 | /// 45 | /// 46 | /// 47 | /// 48 | public static bool IsIn(this T thisValue, params T[] values) 49 | { 50 | return values.Contains(thisValue); 51 | } 52 | 53 | /// 54 | /// 在里面吗? 55 | /// 56 | /// 57 | /// 58 | /// 59 | public static bool IsContainsIn(this string thisValue, params string[] inValues) 60 | { 61 | return inValues.Any(it => thisValue.Contains(it)); 62 | } 63 | 64 | /// 65 | /// 是null或""? 66 | /// 67 | /// 68 | public static bool IsNullOrEmpty(this object thisValue) 69 | { 70 | if (thisValue == null || thisValue == DBNull.Value) return true; 71 | return thisValue.ToString() == ""; 72 | } 73 | /// 74 | /// 是null或""? 75 | /// 76 | /// 77 | public static bool IsNullOrEmpty(this Guid? thisValue) 78 | { 79 | if (thisValue == null) return true; 80 | return thisValue == Guid.Empty; 81 | } 82 | /// 83 | /// 是null或""? 84 | /// 85 | /// 86 | public static bool IsNullOrEmpty(this Guid thisValue) 87 | { 88 | if (thisValue == null) return true; 89 | return thisValue == Guid.Empty; 90 | } 91 | 92 | /// 93 | /// 有值?(与IsNullOrEmpty相反) 94 | /// 95 | /// 96 | public static bool IsValuable(this object thisValue) 97 | { 98 | if (thisValue == null || thisValue == DBNull.Value) return false; 99 | return thisValue.ToString() != ""; 100 | } 101 | /// 102 | /// 有值?(与IsNullOrEmpty相反) 103 | /// 104 | /// 105 | public static bool IsValuable(this IEnumerable thisValue) 106 | { 107 | if (thisValue == null || thisValue.Count() == 0) return false; 108 | return true; 109 | } 110 | 111 | /// 112 | /// 是零? 113 | /// 114 | /// 115 | /// 116 | public static bool IsZero(this object thisValue) 117 | { 118 | return (thisValue == null || thisValue.ToString() == "0"); 119 | } 120 | 121 | /// 122 | /// 是INT? 123 | /// 124 | /// 125 | /// 126 | public static bool IsInt(this object thisValue) 127 | { 128 | if (thisValue == null) return false; 129 | return Regex.IsMatch(thisValue.ToString(), @"^\d+$"); 130 | } 131 | /// 132 | /// 不是INT? 133 | /// 134 | /// 135 | /// 136 | public static bool IsNoInt(this object thisValue) 137 | { 138 | if (thisValue == null) return true; 139 | return !Regex.IsMatch(thisValue.ToString(), @"^\d+$"); 140 | } 141 | 142 | /// 143 | /// 是金钱? 144 | /// 145 | /// 146 | /// 147 | public static bool IsMoney(this object thisValue) 148 | { 149 | if (thisValue == null) return false; 150 | double outValue = 0; 151 | return double.TryParse(thisValue.ToString(), out outValue); 152 | } 153 | 154 | /// 155 | /// 是GUID? 156 | /// 157 | /// 158 | /// 159 | public static bool IsGuid(this object thisValue) 160 | { 161 | if (thisValue == null) return false; 162 | Guid outValue = Guid.Empty; 163 | return Guid.TryParse(thisValue.ToString(), out outValue); 164 | } 165 | 166 | /// 167 | /// 是时间? 168 | /// 169 | /// 170 | /// 171 | public static bool IsDate(this object thisValue) 172 | { 173 | if (thisValue == null) return false; 174 | DateTime outValue = DateTime.MinValue; 175 | return DateTime.TryParse(thisValue.ToString(), out outValue); 176 | } 177 | 178 | /// 179 | /// 是邮箱? 180 | /// 181 | /// 182 | /// 183 | public static bool IsEamil(this object thisValue) 184 | { 185 | if (thisValue == null) return false; 186 | return Regex.IsMatch(thisValue.ToString(), @"^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$"); 187 | } 188 | 189 | /// 190 | /// 是手机? 191 | /// 192 | /// 193 | /// 194 | public static bool IsMobile(this object thisValue) 195 | { 196 | if (thisValue == null) return false; 197 | return Regex.IsMatch(thisValue.ToString(), @"^\d{11}$"); 198 | } 199 | 200 | /// 201 | /// 是座机? 202 | /// 203 | public static bool IsTelephone(this object thisValue) 204 | { 205 | if (thisValue == null) return false; 206 | return System.Text.RegularExpressions.Regex.IsMatch(thisValue.ToString(), @"^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{8}$"); 207 | 208 | } 209 | 210 | /// 211 | /// 是身份证? 212 | /// 213 | /// 214 | /// 215 | public static bool IsIDcard(this object thisValue) 216 | { 217 | if (thisValue == null) return false; 218 | return System.Text.RegularExpressions.Regex.IsMatch(thisValue.ToString(), @"^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$"); 219 | } 220 | 221 | /// 222 | /// 是传真? 223 | /// 224 | /// 225 | /// 226 | public static bool IsFax(this object thisValue) 227 | { 228 | if (thisValue == null) return false; 229 | return System.Text.RegularExpressions.Regex.IsMatch(thisValue.ToString(), @"^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$"); 230 | } 231 | 232 | /// 233 | /// 是适合正则匹配? 234 | /// 235 | /// 236 | /// 237 | /// 238 | public static bool IsMatch(this object thisValue, string pattern) 239 | { 240 | if (thisValue == null) return false; 241 | Regex reg = new Regex(pattern); 242 | return reg.IsMatch(thisValue.ToString()); 243 | } 244 | 245 | /// 246 | /// 是否是动态类型 247 | /// 248 | /// 249 | /// 250 | public static bool IsAnonymousType(this Type type) 251 | { 252 | string typeName = type.Name; 253 | return typeName.Contains("<>") && typeName.Contains("__") && typeName.Contains("AnonymousType"); 254 | } 255 | /// 256 | /// 是List类型 257 | /// 258 | /// 259 | /// 260 | public static bool IsCollectionsList(this string thisValue) 261 | { 262 | return (thisValue + "").StartsWith("System.Collections.Generic.List"); 263 | } 264 | /// 265 | /// 是string[]类型 266 | /// 267 | /// 268 | /// 269 | public static bool IsStringArray(this string thisValue) 270 | { 271 | return (thisValue + "").IsMatch(@"System\.[a-z,A-Z,0-9]+?\[\]"); 272 | } 273 | /// 274 | /// 是Enumerable 275 | /// 276 | /// 277 | /// 278 | public static bool IsEnumerable(this string thisValue) 279 | { 280 | return (thisValue + "").StartsWith("System.Linq.Enumerable"); 281 | } 282 | } 283 | } 284 | -------------------------------------------------------------------------------- /SqlSugar/Tool/LanguageHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLiteSugar 7 | { 8 | /// 9 | /// ** 描述:多语言视图帮助类 10 | /// ** 创始时间:2016-8-7 11 | /// ** 修改时间:- 12 | /// ** 作者:孙凯旋 13 | /// ** 使用说明: 14 | /// 15 | public class LanguageHelper 16 | { 17 | /// 18 | /// 多语言视图的前缀 19 | /// 20 | public static string PreSuffix = "_$_"; 21 | /// 22 | /// 获取所有需要生成多语言的视图名称 23 | /// 24 | /// 25 | /// 26 | internal static List GetLanguageViewNameList(SqlSugarClient db) 27 | { 28 | string key = "LanguageHelper.GetViewNameList"; 29 | var cm = CacheManager>.GetInstance(); 30 | if (cm.ContainsKey(key)) 31 | { 32 | return cm[key]; 33 | } 34 | else 35 | { 36 | var list = db.SqlQuery(@" 37 | select a.name from sys.objects a 38 | JOIN sys.sql_modules b on a.[object_id]=b.[object_id] 39 | where [type]='v' 40 | and b.[definition] like '%" + db.Language.ReplaceViewStringKey + @"%' 41 | and a.name not like '%"+PreSuffix+@"%' 42 | ").ToList(); 43 | cm.Add(key, list, cm.Day); 44 | return list; 45 | } 46 | 47 | } 48 | 49 | /// 50 | /// 创建多语言视图,带有LanguageId=1的所有有视图1替换成languageValue 并且新创视图 名称为 原有视图名+_$_+suffix 51 | /// 52 | /// 53 | public static void UpdateView(PubModel.Language lan, SqlSugarClient db) 54 | { 55 | if (lan == null) return; 56 | if (lan.Suffix.IsNullOrEmpty()) 57 | { 58 | Check.Exception(true, "LanguageHelper.lan.Suffix is Null Or Empty"); 59 | } 60 | if (PreSuffix.IsNullOrEmpty()) 61 | { 62 | Check.Exception(true, "LanguageHelper.PreSuffix is Null Or Empty"); 63 | } 64 | 65 | 66 | if (!lan.Suffix.StartsWith(PreSuffix)) 67 | { 68 | lan.Suffix = PreSuffix + lan.Suffix; 69 | } 70 | 71 | string sql = @" 72 | 73 | --验证参数传递规则 74 | if LEFT(ltrim(@Suffix),3)<>'" + PreSuffix + @"' 75 | begin 76 | raiserror('参数传递格式不规范',16,1) 77 | return; 78 | end 79 | else 80 | if(ISNULL("+lan.LanguageValue+@",'')='') 81 | begin 82 | raiserror('参数传递格式不规范',16,1) 83 | return; 84 | end 85 | 86 | declare 87 | @name varchar(100), --视图名称 88 | @definition varchar(max) --视图脚本 89 | --删除数据库里面所有带传递参数几号的视图 90 | declare my_cursor cursor for 91 | select a.name,b.[definition] from sys.objects a 92 | JOIN sys.sql_modules b on a.[object_id]=b.[object_id] 93 | where [type]='v' 94 | and b.[definition] like '%" + lan.ReplaceViewStringKey + @"%' 95 | and a.name not like '%"+PreSuffix+@"%' 96 | --打开处理器 97 | open my_cursor 98 | fetch next from my_cursor into @name,@definition 99 | while @@FETCH_STATUS=0 100 | begin 101 | --脚本查询语言ID更改,并且更改新脚本语言的对象名称 102 | set @definition=REPLACE( 103 | REPLACE( 104 | @definition, 105 | '" + lan.ReplaceViewStringKey + @"', 106 | '" + string.Format(lan.ReplaceViewStringValue, lan.LanguageValue) + @"' 107 | ), 108 | @name, 109 | @name+@Suffix 110 | ) 111 | --判断新脚本语言的对象名称是否存在,存在删除 112 | exec( 113 | ' 114 | if object_id('''+@name+@Suffix+''',''v'') is not null 115 | begin 116 | drop view '+@name+@Suffix+' 117 | end 118 | 119 | ' 120 | ) 121 | exec(@definition) 122 | fetch next from my_cursor into @name,@definition 123 | end 124 | close my_cursor 125 | deallocate my_cursor 126 | "; 127 | 128 | db.ExecuteCommand(sql, new { Suffix = lan.Suffix }); 129 | 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /SqlSugar/Tool/PubConvert.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLiteSugar 7 | { 8 | /// 9 | /// ** 描述:公用转换函数 10 | /// ** 创始时间:2015-6-9 11 | /// ** 修改时间:- 12 | /// ** 作者:sunkaixuan 13 | /// ** 使用说明: 14 | /// 15 | public static class PubConvert 16 | { 17 | #region 强转成int 如果失败返回 0 18 | /// 19 | /// 强转成int 如果失败返回 0 20 | /// 21 | /// 22 | /// 23 | public static int ObjToInt(this object thisValue) 24 | { 25 | int reval = 0; 26 | if (thisValue == null) return 0; 27 | if (thisValue.GetType().IsEnum) return Convert.ToInt32(thisValue); 28 | if (thisValue != null && thisValue != DBNull.Value && int.TryParse(thisValue.ToString(), out reval)) 29 | { 30 | return reval; 31 | } 32 | return reval; 33 | } 34 | #endregion 35 | #region 强转成int 如果失败返回 errorValue 36 | /// 37 | /// 强转成int 如果失败返回 errorValue 38 | /// 39 | /// 40 | /// 41 | /// 42 | public static int ObjToInt(this object thisValue, int errorValue) 43 | { 44 | int reval = 0; 45 | if (thisValue != null &&thisValue != DBNull.Value&& int.TryParse(thisValue.ToString(), out reval)) 46 | { 47 | return reval; 48 | } 49 | return errorValue; 50 | } 51 | #endregion 52 | #region 强转成double 如果失败返回 0 53 | /// 54 | /// 强转成money 如果失败返回 0 55 | /// 56 | /// 57 | /// 58 | public static double ObjToMoney(this object thisValue) 59 | { 60 | double reval = 0; 61 | if (thisValue != null &&thisValue != DBNull.Value&& double.TryParse(thisValue.ToString(), out reval)) 62 | { 63 | return reval; 64 | } 65 | return 0; 66 | } 67 | #endregion 68 | #region 强转成double 如果失败返回 errorValue 69 | /// 70 | /// 强转成double 如果失败返回 errorValue 71 | /// 72 | /// 73 | /// 74 | /// 75 | public static double ObjToMoney(this object thisValue, double errorValue) 76 | { 77 | double reval = 0; 78 | if (thisValue != null &&thisValue != DBNull.Value&& double.TryParse(thisValue.ToString(), out reval)) 79 | { 80 | return reval; 81 | } 82 | return errorValue; 83 | } 84 | #endregion 85 | #region 强转成string 如果失败返回 "" 86 | /// 87 | /// 强转成string 如果失败返回 "" 88 | /// 89 | /// 90 | /// 91 | public static string ObjToString(this object thisValue) 92 | { 93 | if (thisValue != null) return thisValue.ToString().Trim(); 94 | return ""; 95 | } 96 | #endregion 97 | #region 强转成string 如果失败返回 errorValue 98 | /// 99 | /// 强转成string 如果失败返回 str 100 | /// 101 | /// 102 | /// 103 | /// 104 | public static string ObjToString(this object thisValue, string errorValue) 105 | { 106 | if (thisValue != null) return thisValue.ToString().Trim(); 107 | return errorValue; 108 | } 109 | #endregion 110 | #region 强转成Decimal 如果失败返回 0 111 | /// 112 | /// 强转成Decimal 如果失败返回 0 113 | /// 114 | /// 115 | /// 116 | public static Decimal ObjToDecimal(this object thisValue) 117 | { 118 | Decimal reval = 0; 119 | if (thisValue != null &&thisValue != DBNull.Value&& decimal.TryParse(thisValue.ToString(), out reval)) 120 | { 121 | return reval; 122 | } 123 | return 0; 124 | } 125 | #endregion 126 | #region 强转成Decimal 如果失败返回 errorValue 127 | /// 128 | /// 强转成Decimal 如果失败返回 errorValue 129 | /// 130 | /// 131 | /// 132 | /// 133 | public static Decimal ObjToDecimal(this object thisValue, decimal errorValue) 134 | { 135 | Decimal reval = 0; 136 | if (thisValue != null &&thisValue != DBNull.Value&& decimal.TryParse(thisValue.ToString(), out reval)) 137 | { 138 | return reval; 139 | } 140 | return errorValue; 141 | } 142 | #endregion 143 | #region 强转成DateTime 如果失败返回 DateTime.MinValue 144 | /// 145 | /// 强转成DateTime 如果失败返回 DateTime.MinValue 146 | /// 147 | /// 148 | /// 149 | public static DateTime ObjToDate(this object thisValue) 150 | { 151 | DateTime reval = DateTime.MinValue; 152 | if (thisValue != null &&thisValue != DBNull.Value&& DateTime.TryParse(thisValue.ToString(), out reval)) 153 | { 154 | return reval; 155 | } 156 | return reval; 157 | } 158 | #endregion 159 | #region 强转成DateTime 如果失败返回 errorValue 160 | /// 161 | /// 强转成DateTime 如果失败返回 errorValue 162 | /// 163 | /// 164 | /// 165 | /// 166 | public static DateTime ObjToDate(this object thisValue, DateTime errorValue) 167 | { 168 | DateTime reval = DateTime.MinValue; 169 | if (thisValue != null &&thisValue != DBNull.Value&& DateTime.TryParse(thisValue.ToString(), out reval)) 170 | { 171 | return reval; 172 | } 173 | return errorValue; 174 | } 175 | #endregion 176 | #region 强转成Bool 如果失败返回 false 177 | /// 178 | /// 强转成Bool 如果失败返回 false 179 | /// 180 | /// 181 | /// 182 | public static bool ObjToBool(this object thisValue) 183 | { 184 | bool reval = false; 185 | if (thisValue != null && thisValue != DBNull.Value && bool.TryParse(thisValue.ToString(), out reval)) 186 | { 187 | return reval; 188 | } 189 | return reval; 190 | } 191 | #endregion 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /SqlSugar/Tool/SqlException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLiteSugar 7 | { 8 | /// 9 | /// ** 描述:SqlSugar自定义异常 10 | /// ** 创始时间:2015-7-13 11 | /// ** 修改时间:- 12 | /// ** 作者:sunkaixuan 13 | /// ** 使用说明: 14 | /// 15 | public class SqlSugarException : Exception 16 | { 17 | /// 18 | /// SqlSugar异常 19 | /// 20 | /// 错误信息 21 | public SqlSugarException(string message) 22 | : base(message) 23 | { 24 | 25 | } 26 | /// 27 | /// SqlSugar异常 28 | /// 29 | /// 错误信息 30 | /// ORM生成的SQL 31 | public SqlSugarException(string message, string sql) 32 | : base(GetMessage(message, sql)) 33 | { 34 | 35 | } 36 | /// 37 | /// SqlSugar异常 38 | /// 39 | /// 错误信息 40 | /// ORM生成的SQL 41 | /// 错误函数的参数 42 | public SqlSugarException(string message, string sql, object pars) 43 | : base(GetMessage(message, sql, pars)) 44 | { 45 | 46 | } 47 | /// 48 | /// SqlSugar异常 49 | /// 50 | /// 错误信息 51 | /// 错误函数的参数 52 | public SqlSugarException(string message,object pars) 53 | : base(GetMessage(message,pars)) 54 | { 55 | 56 | } 57 | 58 | private static string GetMessage(string message, object pars) 59 | { 60 | var parsStr = string.Empty; ; 61 | if (pars != null) 62 | { 63 | parsStr = JsonConverter.Serialize(pars); 64 | } 65 | var reval = GetLineMessage("错误信息", message) + GetLineMessage("函数参数", parsStr); 66 | return reval; 67 | 68 | } 69 | 70 | 71 | private static string GetMessage(string message, string sql, object pars) 72 | { 73 | if (pars == null) 74 | { 75 | return GetMessage(message, sql); 76 | } 77 | else 78 | { 79 | var reval = GetLineMessage("错误信息 ", message) + GetLineMessage("ORM生成的Sql", sql) + GetLineMessage("函数参数 ", JsonConverter.Serialize(pars)); 80 | return reval; 81 | } 82 | } 83 | 84 | 85 | private static string GetMessage(string message, string sql) 86 | { 87 | var reval = GetLineMessage("错误信息 ", message) + GetLineMessage("ORM生成的Sql", sql); 88 | return reval; 89 | } 90 | 91 | private static string GetLineMessage(string key, string value) 92 | { 93 | return string.Format("{0} : 【{1}】\r\n", key, value); 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /SqlSugar/Tool/SqlSugarTool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Data; 6 | using System.Reflection; 7 | using System.Data.SQLite; 8 | using System.Linq.Expressions; 9 | using System.Text.RegularExpressions; 10 | 11 | namespace SQLiteSugar 12 | { 13 | /// 14 | /// ** 描述:SqlSugar工具类 15 | /// ** 创始时间:2015-7-13 16 | /// ** 修改时间:- 17 | /// ** 作者:sunkaixuan 18 | /// ** 使用说明: 19 | /// 20 | public partial class SqlSugarTool 21 | { 22 | internal static Type StringType = typeof(string); 23 | internal static Type IntType = typeof(int); 24 | internal static Type DecType = typeof(decimal); 25 | internal static Type GuidType = typeof(Guid); 26 | internal static Type DateType = typeof(DateTime); 27 | internal static Type ByteType = typeof(Byte); 28 | internal static Type BoolType = typeof(bool); 29 | internal static Type ObjType = typeof(object); 30 | internal static Type Dob = typeof(double); 31 | internal static Type DicSS = typeof(KeyValuePair); 32 | internal static Type DicSi = typeof(KeyValuePair); 33 | internal static Type Dicii = typeof(KeyValuePair); 34 | internal static Type DicOO = typeof(KeyValuePair); 35 | internal static Type DicSo = typeof(KeyValuePair); 36 | internal static Type DicIS = typeof(KeyValuePair); 37 | internal static Type DicArraySS = typeof(Dictionary); 38 | internal static Type DicArraySO = typeof(Dictionary); 39 | 40 | /// 41 | /// Reader转成T的集合 42 | /// 43 | /// 44 | /// 45 | /// 46 | /// 47 | /// 48 | /// 49 | /// 50 | internal static List DataReaderToList(Type type, IDataReader dr, string fields, bool isClose = true, bool isTry = true) 51 | { 52 | if (type.Name.Contains("KeyValuePair")) 53 | { 54 | List strReval = new List(); 55 | FillValueTypeToDictionary(type, dr, strReval); 56 | return strReval; 57 | } 58 | //值类型 59 | else if (type.IsValueType || type == SqlSugarTool.StringType) 60 | { 61 | List strReval = new List(); 62 | FillValueTypeToDr(type, dr, strReval); 63 | return strReval; 64 | } 65 | //数组类型 66 | else if (type.IsArray) 67 | { 68 | List strReval = new List(); 69 | FillValueTypeToArray(type, dr, strReval); 70 | return strReval; 71 | } 72 | 73 | 74 | var cacheManager = CacheManager>.GetInstance(); 75 | string key = "DataReaderToList." + fields + type.FullName; 76 | IDataReaderEntityBuilder eblist = null; 77 | if (cacheManager.ContainsKey(key)) 78 | { 79 | eblist = cacheManager[key]; 80 | } 81 | else 82 | { 83 | eblist = IDataReaderEntityBuilder.CreateBuilder(type, dr); 84 | cacheManager.Add(key, eblist, cacheManager.Day); 85 | } 86 | List list = new List(); 87 | try 88 | { 89 | if (dr == null) return list; 90 | while (dr.Read()) 91 | { 92 | list.Add(eblist.Build(dr)); 93 | } 94 | if (isClose) { dr.Close(); dr.Dispose(); dr = null; } 95 | } 96 | catch (Exception ex) 97 | { 98 | if (isClose) { dr.Close(); dr.Dispose(); dr = null; } 99 | Check.Exception(true, "错误信息:实体映射出错。\r\n错误详情:{0}", ex.Message); 100 | } 101 | return list; 102 | } 103 | 104 | private static void FillValueTypeToDr(Type type, IDataReader dr, List strReval) 105 | { 106 | using (IDataReader re = dr) 107 | { 108 | while (re.Read()) 109 | { 110 | strReval.Add((T)Convert.ChangeType(re.GetValue(0), type)); 111 | } 112 | } 113 | } 114 | 115 | 116 | /// 117 | /// 设置参数Size 118 | /// 119 | /// 120 | public static void SetParSize(SQLiteParameter par) 121 | { 122 | int size = par.Size; 123 | if (size < 4000) 124 | { 125 | par.Size = 4000; 126 | } 127 | } 128 | 129 | /// 130 | /// 将实体对象转换成SqlParameter[] 131 | /// 132 | /// 133 | /// 134 | /// 135 | public static SQLiteParameter[] GetParameters(object obj, PropertyInfo[] pis = null) 136 | { 137 | List listParams = new List(); 138 | if (obj != null) 139 | { 140 | var type = obj.GetType(); 141 | var isDic = type.IsIn(SqlSugarTool.DicArraySO, SqlSugarTool.DicArraySS); 142 | if (isDic) 143 | { 144 | if (type == SqlSugarTool.DicArraySO) 145 | { 146 | var newObj = (Dictionary)obj; 147 | var pars = newObj.Select(it => new SQLiteParameter("@" + it.Key, it.Value)); 148 | foreach (var par in pars) 149 | { 150 | SetParSize(par); 151 | } 152 | listParams.AddRange(pars); 153 | } 154 | else 155 | { 156 | 157 | var newObj = (Dictionary)obj; 158 | var pars = newObj.Select(it => new SQLiteParameter("@" + it.Key, it.Value)); 159 | foreach (var par in pars) 160 | { 161 | SetParSize(par); 162 | } 163 | listParams.AddRange(pars); ; 164 | } 165 | } 166 | else 167 | { 168 | PropertyInfo[] propertiesObj = null; 169 | if (pis != null) 170 | { 171 | propertiesObj = pis; 172 | } 173 | else { 174 | propertiesObj=type.GetProperties(); 175 | } 176 | string replaceGuid = Guid.NewGuid().ToString(); 177 | foreach (PropertyInfo r in propertiesObj) 178 | { 179 | var value = r.GetValue(obj, null); 180 | if (r.PropertyType.IsEnum) 181 | { 182 | value = Convert.ToInt64(value); 183 | } 184 | if (value == null) value = DBNull.Value; 185 | if (r.Name.ToLower().Contains("hierarchyid")) 186 | { 187 | 188 | } 189 | else 190 | { 191 | var par = new SQLiteParameter("@" + r.Name, value); 192 | SetParSize(par); 193 | listParams.Add(par); 194 | } 195 | } 196 | } 197 | } 198 | return listParams.ToArray(); 199 | } 200 | 201 | /// 202 | /// 将实体对象转换成 Dictionary《string, string》 203 | /// 204 | /// 205 | /// 206 | internal static Dictionary GetObjectToDictionary(object obj) 207 | { 208 | 209 | Dictionary reval = new Dictionary(); 210 | if (obj == null) return reval; 211 | var type = obj.GetType(); 212 | var isDic = type.IsIn(SqlSugarTool.DicArraySO, SqlSugarTool.DicArraySS); 213 | if (isDic) 214 | { 215 | if (type == SqlSugarTool.DicArraySO) 216 | { 217 | return (Dictionary)obj; 218 | } 219 | else 220 | { 221 | var newObj = (Dictionary)obj; 222 | foreach (var item in newObj) 223 | { 224 | reval.Add(item.Key, item.Value); 225 | } 226 | return reval; 227 | } 228 | } 229 | else 230 | { 231 | var propertiesObj = type.GetProperties(); 232 | string replaceGuid = Guid.NewGuid().ToString(); 233 | foreach (PropertyInfo r in propertiesObj) 234 | { 235 | var val = r.GetValue(obj, null); 236 | if (r.PropertyType.IsEnum) 237 | { 238 | val =Convert.ToInt64(val); 239 | } 240 | reval.Add(r.Name, val == null ? DBNull.Value : val); 241 | } 242 | 243 | return reval; 244 | } 245 | } 246 | 247 | /// 248 | /// 获取type属性cache 249 | /// 250 | /// 251 | /// 252 | /// 253 | /// 254 | internal static PropertyInfo[] GetGetPropertiesByCache(Type type, string cachePropertiesKey, CacheManager cachePropertiesManager) 255 | { 256 | PropertyInfo[] props = null; 257 | if (cachePropertiesManager.ContainsKey(cachePropertiesKey)) 258 | { 259 | props = cachePropertiesManager[cachePropertiesKey]; 260 | } 261 | else 262 | { 263 | props = type.GetProperties(); 264 | cachePropertiesManager.Add(cachePropertiesKey, props, cachePropertiesManager.Day); 265 | } 266 | return props; 267 | } 268 | 269 | 270 | /// 271 | /// 判段是否包含主键 272 | /// 273 | /// 274 | /// 275 | /// 276 | internal static bool IsPrimaryKey(SqlSugarClient db, string tableName) 277 | { 278 | return GetPrimaryKeyByTableName(db, tableName) != null; 279 | } 280 | 281 | 282 | /// 283 | /// 处理like条件的通配符 284 | /// 285 | /// 286 | /// 287 | public static string SqlLikeWordEncode(string word) 288 | { 289 | if (word == null) return word; 290 | return Regex.Replace(word, @"(\[|\%)", "[$1]"); 291 | } 292 | 293 | /// 294 | /// 获取属性值 295 | /// 296 | /// 297 | /// 298 | /// 299 | internal static Guid GetPropertyValue(object obj, string property) 300 | { 301 | PropertyInfo propertyInfo = obj.GetType().GetProperty(property); 302 | return (Guid)propertyInfo.GetValue(obj, null); 303 | } 304 | 305 | /// 306 | /// 使用页面自动填充sqlParameter时 Request.Form出现特殊字符时可以重写Request.Form方法,使用时注意加锁并且用到将该值设为null 307 | /// 308 | public static Func SpecialRequestForm = null; 309 | 310 | 311 | /// 312 | /// 获取最底层类型 313 | /// 314 | /// 315 | /// 316 | /// 317 | internal static Type GetUnderType(PropertyInfo propertyInfo, ref bool isNullable) 318 | { 319 | Type unType = Nullable.GetUnderlyingType(propertyInfo.PropertyType); 320 | isNullable = unType != null; 321 | unType = unType ?? propertyInfo.PropertyType; 322 | return unType; 323 | } 324 | } 325 | } 326 | -------------------------------------------------------------------------------- /SqlSugar/Tool/SqlSugarToolCoreDiff.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Data; 6 | using System.Web; 7 | using System.Data.SQLite; 8 | 9 | namespace SQLiteSugar 10 | { 11 | /// 12 | /// SqlSugarTool局部类与Core有差异的部分(方便工具移植到.NetCore版本) 13 | /// 14 | public partial class SqlSugarTool 15 | { 16 | private static void FillValueTypeToDictionary(Type type, IDataReader dr, List strReval) 17 | { 18 | using (IDataReader re = dr) 19 | { 20 | Dictionary reval = new Dictionary(); 21 | while (re.Read()) 22 | { 23 | if (SqlSugarTool.DicOO == type) 24 | { 25 | var kv = new KeyValuePair((object)Convert.ChangeType(re.GetValue(0), typeof(object)), (int)Convert.ChangeType(re.GetValue(1), typeof(object))); 26 | strReval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair))); 27 | } 28 | else if (SqlSugarTool.Dicii == type) 29 | { 30 | var kv = new KeyValuePair((int)Convert.ChangeType(re.GetValue(0), typeof(int)), (int)Convert.ChangeType(re.GetValue(1), typeof(int))); 31 | strReval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair))); 32 | } 33 | else if (SqlSugarTool.DicSi == type) 34 | { 35 | var kv = new KeyValuePair((string)Convert.ChangeType(re.GetValue(0), typeof(string)), (int)Convert.ChangeType(re.GetValue(1), typeof(int))); 36 | strReval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair))); 37 | } 38 | else if (SqlSugarTool.DicSo == type) 39 | { 40 | var kv = new KeyValuePair((string)Convert.ChangeType(re.GetValue(0), typeof(string)), (object)Convert.ChangeType(re.GetValue(1), typeof(object))); 41 | strReval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair))); 42 | } 43 | else if (SqlSugarTool.DicSS == type) 44 | { 45 | var kv = new KeyValuePair((string)Convert.ChangeType(re.GetValue(0), typeof(string)), (string)Convert.ChangeType(re.GetValue(1), typeof(string))); 46 | strReval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair))); 47 | } 48 | else 49 | { 50 | Check.Exception(true, "暂时不支持该类型的Dictionary 你可以试试 Dictionary或者联系作者!!"); 51 | } 52 | } 53 | } 54 | } 55 | 56 | private static void FillValueTypeToArray(Type type, IDataReader dr, List strReval) 57 | { 58 | using (IDataReader re = dr) 59 | { 60 | int count = dr.FieldCount; 61 | var childType = type.GetElementType(); 62 | while (re.Read()) 63 | { 64 | object[] array = new object[count]; 65 | for (int i = 0; i < count; i++) 66 | { 67 | array[i] = Convert.ChangeType(re.GetValue(i), childType); 68 | } 69 | if (childType == SqlSugarTool.StringType) 70 | strReval.Add((T)Convert.ChangeType(array.Select(it => (string)it).ToArray(), type)); 71 | else if (childType == SqlSugarTool.ObjType) 72 | strReval.Add((T)Convert.ChangeType(array.Select(it => (object)it).ToArray(), type)); 73 | else if (childType == SqlSugarTool.BoolType) 74 | strReval.Add((T)Convert.ChangeType(array.Select(it => (bool)it).ToArray(), type)); 75 | else if (childType == SqlSugarTool.ByteType) 76 | strReval.Add((T)Convert.ChangeType(array.Select(it => (byte)it).ToArray(), type)); 77 | else if (childType == SqlSugarTool.DecType) 78 | strReval.Add((T)Convert.ChangeType(array.Select(it => (decimal)it).ToArray(), type)); 79 | else if (childType == SqlSugarTool.GuidType) 80 | strReval.Add((T)Convert.ChangeType(array.Select(it => (Guid)it).ToArray(), type)); 81 | else if (childType == SqlSugarTool.DateType) 82 | strReval.Add((T)Convert.ChangeType(array.Select(it => (DateTime)it).ToArray(), type)); 83 | else if (childType == SqlSugarTool.IntType) 84 | strReval.Add((T)Convert.ChangeType(array.Select(it => (int)it).ToArray(), type)); 85 | else 86 | Check.Exception(true, "暂时不支持该类型的Array 你可以试试 object[] 或者联系作者!!"); 87 | } 88 | } 89 | } 90 | 91 | /// 92 | /// 获取参数到键值集合根据页面Request参数 93 | /// 94 | /// 95 | public static Dictionary GetParameterDictionary(bool isNotNullAndEmpty = false) 96 | { 97 | if (SpecialRequestForm == null) 98 | { 99 | Dictionary paraDictionaryByGet = HttpContext.Current.Request.QueryString.Keys.Cast() 100 | .ToDictionary(k => k, v => HttpContext.Current.Request.QueryString[v]); 101 | 102 | Dictionary paraDictionaryByPost = HttpContext.Current.Request.Form.Keys.Cast() 103 | .ToDictionary(k => k, v => HttpContext.Current.Request.Form[v]); 104 | 105 | var paraDictionarAll = paraDictionaryByGet.Union(paraDictionaryByPost); 106 | if (isNotNullAndEmpty) 107 | { 108 | paraDictionarAll = paraDictionarAll.Where(it => !string.IsNullOrEmpty(it.Value)); 109 | } 110 | return paraDictionarAll.ToDictionary((keyItem) => keyItem.Key, (valueItem) => valueItem.Value); 111 | } 112 | else 113 | { 114 | 115 | var pars = HttpContext.Current.Request.Form.Keys.Cast() 116 | .ToDictionary(k => k, v => SpecialRequestForm(v)).Where(it => true); 117 | if (isNotNullAndEmpty) 118 | { 119 | pars = pars.Where(it => !string.IsNullOrEmpty(it.Value)); 120 | } 121 | return pars.ToDictionary((keyItem) => keyItem.Key, (valueItem) => valueItem.Value); 122 | } 123 | } 124 | 125 | /// 126 | /// 获取参数到键值集合根据页面Request参数 127 | /// 128 | /// 129 | public static SQLiteParameter[] GetParameterArray(bool isNotNullAndEmpty = false) 130 | { 131 | Dictionary paraDictionaryByGet = HttpContext.Current.Request.QueryString.Keys.Cast() 132 | .ToDictionary(k => k, v => HttpContext.Current.Request.QueryString[v]); 133 | 134 | Dictionary paraDictionaryByPost = HttpContext.Current.Request.Form.Keys.Cast() 135 | .ToDictionary(k => k, v => HttpContext.Current.Request.Form[v]); 136 | 137 | var paraDictionarAll = paraDictionaryByGet.Union(paraDictionaryByPost); 138 | if (isNotNullAndEmpty) 139 | { 140 | paraDictionarAll = paraDictionarAll.Where(it => !string.IsNullOrEmpty(it.Value)); 141 | } 142 | return paraDictionarAll.Select(it => new SQLiteParameter(SqlSugarTool.ParSymbol + it.Key, it.Value)).ToArray(); 143 | } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /SqlSugar/Tool/SqlSugarToolExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.RegularExpressions; 6 | using System.Data.SQLite; 7 | 8 | namespace SQLiteSugar 9 | { 10 | /// 11 | /// ** 描述:SqlSugar扩展工具类 12 | /// ** 创始时间:2015-7-19 13 | /// ** 修改时间:- 14 | /// ** 作者:sunkaixuan 15 | /// ** 使用说明: 16 | /// 17 | public static class SqlSugarToolExtensions 18 | { 19 | 20 | /// 21 | /// 将数组转换成Where In 需要的格式(例如:参数 new int{1,2,3} 反回 "'1','2','3'") 22 | /// 23 | /// 24 | /// 25 | public static string ToJoinSqlInVal(this T[] array) 26 | { 27 | if (array == null || array.Length == 0) 28 | { 29 | return ToSqlValue(string.Empty); 30 | } 31 | else 32 | { 33 | return string.Join(",", array.Where(c => c != null).Select(it => (it + "").ToSuperSqlFilter().ToSqlValue())); 34 | } 35 | } 36 | /// 37 | /// 将字符串转换成SQL参数所需要的格式(例如: 参数value返回'value') 38 | /// 39 | /// 40 | /// 41 | public static string ToSqlValue(this string value) 42 | { 43 | return string.Format("'{0}'", value.ToSqlFilter()); 44 | } 45 | /// 46 | ///SQL注入过滤 47 | /// 48 | /// 49 | /// 50 | public static string ToSqlFilter(this string value) 51 | { 52 | if (!value.IsNullOrEmpty()) 53 | { 54 | if (Regex.IsMatch(value, @"%\d|0x\d|0x[0-9,a-z]{6,300}|(\@.*\=)", RegexOptions.IgnoreCase)) 55 | { 56 | throw new SqlSugarException("查询参数不允许存在特殊字符。"); 57 | } 58 | value = value.Replace("'", "''"); 59 | } 60 | return value; 61 | } 62 | /// 63 | /// 指定数据类型,如果不在指定类当中则引发异常(只允许输入指定字母、数字、下划线、时间、GUID) 64 | /// 65 | /// 66 | /// 67 | public static string ToSuperSqlFilter(this string value) 68 | { 69 | if (value.IsNullOrEmpty()) return value; 70 | if (Regex.IsMatch(value, @"^(\w|\.|\:|\-| |\,)+$")) 71 | { 72 | return value; 73 | } 74 | throw new SqlSugarException("指定类型(只允许输入指定字母、数字、下划线、时间、guid)。"); 75 | } 76 | 77 | /// 78 | /// 获取锁字符串 79 | /// 80 | /// 81 | /// 82 | internal static string GetLockString(this bool isNoLock) 83 | { 84 | return isNoLock ? "WITH(NOLOCK)" : null; ; 85 | } 86 | /// 87 | /// 获取Select需要的字段 88 | /// 89 | /// 90 | /// 91 | internal static string GetSelectFiles(this string selectFileds) 92 | { 93 | return selectFileds.IsNullOrEmpty() ? "*" : selectFileds; 94 | } 95 | /// 96 | /// 97 | /// 98 | /// 99 | /// 100 | internal static string GetGroupBy(this string groupByFileds) 101 | { 102 | return groupByFileds.IsNullOrEmpty() ? "" : " GROUP BY " + groupByFileds; 103 | } 104 | /// 105 | /// 将Request里的参数转成SqlParameter[] 106 | /// 107 | /// 108 | internal static void RequestParasToSqlParameters(SQLiteParameterCollection oldParas) 109 | { 110 | var oldParaList = oldParas.Cast().ToList(); 111 | var paraDictionarAll = SqlSugarTool.GetParameterDictionary(); 112 | if (paraDictionarAll != null && paraDictionarAll.Count() > 0) 113 | { 114 | 115 | foreach (KeyValuePair it in paraDictionarAll) 116 | { 117 | 118 | var par = new SQLiteParameter("@" + it.Key, it.Value); 119 | if (!oldParaList.Any(oldPara => oldPara.ParameterName == ("@" + it.Key))) 120 | { 121 | oldParas.Add(par); 122 | } 123 | } 124 | } 125 | } 126 | /// 127 | /// 获取转释后的表名和列名 128 | /// 129 | /// 130 | /// 131 | public static string GetTranslationSqlName(this string tableName) 132 | { 133 | return SqlSugarTool.GetTranslationSqlName(tableName); 134 | } 135 | /// 136 | /// 获取参数名 137 | /// 138 | /// 139 | /// 140 | internal static string GetSqlParameterName(this string name) 141 | { 142 | return SqlSugarTool.GetSqlParameterName(name); 143 | } 144 | 145 | /// 146 | ///获取没有符号的参数名称 147 | /// 148 | /// 149 | /// 150 | internal static string GetSqlParameterNameNoParSymbol(this string name) 151 | { 152 | return SqlSugarTool.GetSqlParameterNameNoParSymbol(name); 153 | } 154 | 155 | 156 | /// 157 | /// 数组条件筛选 158 | /// 159 | /// 160 | /// 161 | /// 162 | internal static string[] ArrayWhere(this string[] thisValue, Func expression) 163 | { 164 | if (thisValue == null) return null; 165 | thisValue = thisValue.Where(expression).ToArray(); 166 | return thisValue; 167 | } 168 | 169 | /// 170 | /// 数组添加元素 171 | /// 172 | /// 173 | /// 174 | /// 175 | internal static string[] ArrayAdd(this string[] thisValue, params string[] items) 176 | { 177 | if (thisValue == null) thisValue = new string[] { }; 178 | var reval = thisValue.ToList(); 179 | reval.AddRange(items); 180 | thisValue = reval.ToArray(); 181 | return thisValue; 182 | } 183 | 184 | /// 185 | /// 数组移除 186 | /// 187 | /// 188 | /// 189 | /// 190 | internal static string[] ArrayRemove(this string[] thisValue, string item) 191 | { 192 | if (thisValue == null) thisValue = new string[] { }; 193 | var reval = thisValue.ToList(); 194 | reval.Remove(item); 195 | thisValue = reval.ToArray(); 196 | return thisValue; 197 | } 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /SqlSugar/bat.bat: -------------------------------------------------------------------------------- 1 | %~dp0nuget.exe pack %~dp0SQLiteSugar.csproj -OutputDirectory %~dp0 -------------------------------------------------------------------------------- /SqliteSugar.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqliteSugar", "SqlSugar\SqliteSugar.csproj", "{46A17E67-7E3E-4369-9B1F-43BA34BBDAEF}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NewTest", "NewTest\NewTest.csproj", "{EAFE7F79-ABB5-41BA-92A1-1B8764C8885C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Debug|Mixed Platforms = Debug|Mixed Platforms 12 | Debug|x86 = Debug|x86 13 | Release|Any CPU = Release|Any CPU 14 | Release|Mixed Platforms = Release|Mixed Platforms 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {46A17E67-7E3E-4369-9B1F-43BA34BBDAEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {46A17E67-7E3E-4369-9B1F-43BA34BBDAEF}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {46A17E67-7E3E-4369-9B1F-43BA34BBDAEF}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 21 | {46A17E67-7E3E-4369-9B1F-43BA34BBDAEF}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 22 | {46A17E67-7E3E-4369-9B1F-43BA34BBDAEF}.Debug|x86.ActiveCfg = Debug|Any CPU 23 | {46A17E67-7E3E-4369-9B1F-43BA34BBDAEF}.Release|Any CPU.ActiveCfg = Release|Any CPU 24 | {46A17E67-7E3E-4369-9B1F-43BA34BBDAEF}.Release|Any CPU.Build.0 = Release|Any CPU 25 | {46A17E67-7E3E-4369-9B1F-43BA34BBDAEF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 26 | {46A17E67-7E3E-4369-9B1F-43BA34BBDAEF}.Release|Mixed Platforms.Build.0 = Release|Any CPU 27 | {46A17E67-7E3E-4369-9B1F-43BA34BBDAEF}.Release|x86.ActiveCfg = Release|Any CPU 28 | {EAFE7F79-ABB5-41BA-92A1-1B8764C8885C}.Debug|Any CPU.ActiveCfg = Debug|x86 29 | {EAFE7F79-ABB5-41BA-92A1-1B8764C8885C}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 30 | {EAFE7F79-ABB5-41BA-92A1-1B8764C8885C}.Debug|Mixed Platforms.Build.0 = Debug|x86 31 | {EAFE7F79-ABB5-41BA-92A1-1B8764C8885C}.Debug|x86.ActiveCfg = Debug|x86 32 | {EAFE7F79-ABB5-41BA-92A1-1B8764C8885C}.Debug|x86.Build.0 = Debug|x86 33 | {EAFE7F79-ABB5-41BA-92A1-1B8764C8885C}.Release|Any CPU.ActiveCfg = Release|x86 34 | {EAFE7F79-ABB5-41BA-92A1-1B8764C8885C}.Release|Mixed Platforms.ActiveCfg = Release|x86 35 | {EAFE7F79-ABB5-41BA-92A1-1B8764C8885C}.Release|Mixed Platforms.Build.0 = Release|x86 36 | {EAFE7F79-ABB5-41BA-92A1-1B8764C8885C}.Release|x86.ActiveCfg = Release|x86 37 | {EAFE7F79-ABB5-41BA-92A1-1B8764C8885C}.Release|x86.Build.0 = Release|x86 38 | EndGlobalSection 39 | GlobalSection(SolutionProperties) = preSolution 40 | HideSolutionNode = FALSE 41 | EndGlobalSection 42 | EndGlobal 43 | --------------------------------------------------------------------------------