mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 12:28:15 +08:00
ExpreessTree替代反射缓存(1)
This commit is contained in:
@ -66,13 +66,15 @@ namespace FreeSql.Internal.CommonProvider {
|
||||
public List<T> Query<T>(CommandType cmdType, string cmdText, params DbParameter[] cmdParms) {
|
||||
var names = new Dictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
|
||||
var ret = new List<T>();
|
||||
var type = typeof(T);
|
||||
var defaultValue = default(T);
|
||||
ExecuteReader(dr => {
|
||||
if (names.Any() == false)
|
||||
for (var a = 0; a < dr.FieldCount; a++) names.Add(dr.GetName(a), a);
|
||||
object[] values = new object[dr.FieldCount];
|
||||
object[] values = new object[names.Count];
|
||||
dr.GetValues(values);
|
||||
var read = Utils.ExecuteArrayRowReadClassOrTuple(typeof(T), names, values, 0);
|
||||
ret.Add(read.value == null ? default(T) : (T)read.value);
|
||||
var read = Utils.ExecuteArrayRowReadClassOrTuple(type, names, values, 0);
|
||||
ret.Add(read.Value == null ? defaultValue : (T)read.Value);
|
||||
}, cmdType, cmdText, cmdParms);
|
||||
return ret;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ namespace FreeSql.Internal.CommonProvider {
|
||||
var ret = new List<T>();
|
||||
foreach (var row in ds) {
|
||||
var read = Utils.ExecuteArrayRowReadClassOrTuple(typeof(T), names, row);
|
||||
ret.Add(read.value == null ? default(T) : (T) read.value);
|
||||
ret.Add(read.Value == null ? default(T) : (T) read.Value);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ namespace FreeSql.Internal.CommonProvider {
|
||||
var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql, _params.ToArray());
|
||||
foreach (var dr in ds) {
|
||||
var read = Utils.ExecuteArrayRowReadClassOrTuple(type, null, dr);
|
||||
ret.Add(read.value == null ? default(TTuple) : (TTuple)read.value);
|
||||
ret.Add(read.Value == null ? default(TTuple) : (TTuple)read.Value);
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
@ -165,7 +165,7 @@ namespace FreeSql.Internal.CommonProvider {
|
||||
var ds = await _orm.Ado.ExecuteArrayAsync(CommandType.Text, sql, _params.ToArray());
|
||||
foreach (var dr in ds) {
|
||||
var read = Utils.ExecuteArrayRowReadClassOrTuple(type, null, dr);
|
||||
ret.Add(read.value == null ? default(TTuple) : (TTuple)read.value);
|
||||
ret.Add(read.Value == null ? default(TTuple) : (TTuple)read.Value);
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
@ -221,16 +221,12 @@ namespace FreeSql.Internal.CommonProvider {
|
||||
}
|
||||
protected (ReadAnonymousTypeInfo map, string field) GetAllField() {
|
||||
var type = typeof(T1);
|
||||
if (Utils._dicClassConstructor.TryGetValue(type, out var classInfo) == false) {
|
||||
classInfo = new Utils._dicClassConstructorInfo { Constructor = type.GetConstructor(new Type[0]), Properties = type.GetProperties() };
|
||||
Utils._dicClassConstructor.TryAdd(type, classInfo);
|
||||
}
|
||||
var map = new ReadAnonymousTypeInfo { Consturctor = classInfo.Constructor, ConsturctorType = ReadAnonymousTypeInfoConsturctorType.Properties };
|
||||
var map = new ReadAnonymousTypeInfo { Consturctor = type.GetConstructor(new Type[0]), ConsturctorType = ReadAnonymousTypeInfoConsturctorType.Properties };
|
||||
var field = new StringBuilder();
|
||||
var dicfield = new Dictionary<string, bool>();
|
||||
var tb = _tables.First();
|
||||
var index = 0;
|
||||
var ps = classInfo.Properties;
|
||||
var ps = type.GetProperties();
|
||||
foreach (var p in ps) {
|
||||
var child = new ReadAnonymousTypeInfo { Property = p, CsName = p.Name };
|
||||
if (tb.Table.ColumnsByCs.TryGetValue(p.Name, out var col)) { //普通字段
|
||||
|
Reference in New Issue
Block a user