.net core中有哪些被抛弃的类
1、DataTable DataRow SqlDataAdapter DataRow DataColumn DataColumn
虽然这些类不是我ORM核心功能,但是为了保证非Core版本的ORM和Core的语法要一致方便以后升级
于是我就有了一个想法将他们复活,打造一个小巧的DataTable,让更多的老程可以方便的移植到Core。
/// <summary> /// 作者:sunkaixuan /// 创建时间:2016/7/31 /// 修改时间:- /// 说明:让.netCore支持DataTable /// </summary> public class DataTable { public DataColumnCollection Columns = new DataColumnCollection(); public DataRowCollection Rows = new DataRowCollection(); }
public class DataColumn { public DataColumn() { } public DataColumn(string columnName) { this.ColumnName = columnName; } public DataColumn(string columnName, object dataType) { this.ColumnName = columnName; this.DataType = dataType; } public string ColumnName { get; internal set; } public object DataType { get; internal set; } }
public class DataColumnCollection : IEnumerable, ICollection, IEnumerator { public DataColumn this[int thisIndex] { get { return cols[thisIndex]; } } private int index = -1; private List<DataColumn> cols; public int Count { get { if (this.cols == null) { this.cols = new List<DataColumn>(); } return this.cols.Count; } } public void Add(DataColumn col) { if (this.cols == null) { this.cols = new List<DataColumn>(); } this.cols.Add(col); } public bool IsSynchronized { get { return true; } } public object SyncRoot { get { return null; } } public object Current { get { return cols[index]; } } public void CopyTo(Array array, int index) { throw new NotImplementedException(); } // // 摘要: // 获取该集合的 System.Collections.IEnumerator。 // // 返回结果: // 该集合的 System.Collections.IEnumerator。 public IEnumerator GetEnumerator() { return (IEnumerator)this; ; } public bool MoveNext() { index++; var isNext = index < cols.Count; if (!isNext) Reset(); return isNext; } public void Reset() { index = -1; } public bool ContainsKey(string name) { if (this.cols == null) return false; return (this.cols.Any(it => it.ColumnName == name)); } }
DataRowCollection SqlDataAdapter DataRow
配套的SqlHelper
2.GetType的扩展属性发生变更
例如 Type.IsEnum在Core中要写成 Type.GetTypeInfo().IsEnum
于是我将代码进行封装,让语法不变
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Reflection; namespace SqlSugar { public static class TypeExtensions { public static PropertyInfo[] GetProperties(this Type type) { var reval = type.GetTypeInfo().GetProperties(); return reval; } public static PropertyInfo GetProperty(this Type type, string name) { var reval = type.GetTypeInfo().GetProperty(name); return reval; } public static FieldInfo GetField(this Type type, string name) { var reval = type.GetTypeInfo().GetField(name); return reval; } public static bool IsEnum(this Type type) { var reval = type.GetTypeInfo().IsEnum; return reval; } public static MethodInfo GetMethod(this Type type, string name) { var reval = type.GetTypeInfo().GetMethod(name); return reval; } public static MethodInfo GetMethod(this Type type, string name, Type[] types) { var reval = type.GetTypeInfo().GetMethod(name, types); return reval; } public static ConstructorInfo GetConstructor(this Type type, Type[] types) { var reval = type.GetTypeInfo().GetConstructor(types); return reval; } } }
3、System.Web类
因为SqlSugar ORM并没有用到System.Web的功能,所以基本没什么事儿
SqlSugar一款轻量级高性能ORM框架 Core版只有80K功能强大
将Demo进行了整理方便大家使用
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using SqlSugar; using SqlSugarTest.Demos; namespace SqlSugarTest { public class Program { public static void Main(string[] args) { using (SqlSugarClient db = new SqlSugarClient("server=.;uid=sa;pwd=sasa;database=SqlSugarTest")) { var dt = db.GetDataTable("select * from student where [email protected]", new { id = 1 }); //设置执行的DEMO string switch_on = "EnumType"; IDemos demo = null; switch (switch_on) { //ADO.NET基本功能 case "Ado": demo = new Ado(); break; //查询 case "Select": demo = new Select(); break; //插入 case "Insert": demo = new Insert(); break; //更新 case "Update": demo = new Update(); break; //删除 case "Delete": demo = new Delete(); break; //事务 case "Tran": demo = new Tran(); break; //生成实体 case "CreateClass": demo = new CreateClass(); break; //枚举类型的支持 case "EnumType": demo = new EnumType(); break; //除了多库并行计算外的所有功能都已经移植成功更多例子请关注我的博客 } //执行DEMO demo.Init(); Console.WriteLine("执行成功请关闭窗口"); Console.ReadKey(); } } } }
目录更加简洁明了
查询:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
|
更多用法:
http://www.cnblogs.com/sunkaixuan/p/5654695.html 除了并行计算的功能其它都移植成功
源代码:
Core版本
https://github.com/sunkaixuan/ASP_NET_CORE_ORM_SqlSugar
.net 版本
https://github.com/sunkaixuan/SqlSugar