mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 12:28:15 +08:00
v0.0.11 修复IAdo.Query直接查询sql的bug
This commit is contained in:
@ -64,19 +64,19 @@ namespace FreeSql.Internal.CommonProvider {
|
||||
if (isThrowException) throw e;
|
||||
}
|
||||
|
||||
internal static ConcurrentDictionary<Type, Dictionary<string, PropertyInfo>> dicQueryTypeGetProperties = new ConcurrentDictionary<Type, Dictionary<string, PropertyInfo>>();
|
||||
internal static ConcurrentDictionary<Type, PropertyInfo[]> dicQueryTypeGetProperties = new ConcurrentDictionary<Type, PropertyInfo[]>();
|
||||
public List<T> Query<T>(string cmdText, object parms = null) => Query<T>(CommandType.Text, cmdText, GetDbParamtersByObject(cmdText, parms));
|
||||
public List<T> Query<T>(CommandType cmdType, string cmdText, params DbParameter[] cmdParms) {
|
||||
var ret = new List<T>();
|
||||
var type = typeof(T);
|
||||
int[] indexes = null;
|
||||
var props = dicQueryTypeGetProperties.GetOrAdd(type, k => type.GetProperties().ToDictionary(a => a.Name, a => a, StringComparer.CurrentCultureIgnoreCase));
|
||||
var props = dicQueryTypeGetProperties.GetOrAdd(type, k => type.GetProperties());
|
||||
ExecuteReader(dr => {
|
||||
if (indexes == null) {
|
||||
var idxs = new List<int>();
|
||||
var dic = new Dictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
|
||||
for (var a = 0; a < dr.FieldCount; a++)
|
||||
if (props.ContainsKey(dr.GetName(a))) idxs.Add(a);
|
||||
indexes = idxs.ToArray();
|
||||
dic.Add(dr.GetName(a), a);
|
||||
indexes = props.Select(a => dic.TryGetValue(a.Name, out var tryint) ? tryint : -1).ToArray();
|
||||
}
|
||||
ret.Add((T)Utils.ExecuteArrayRowReadClassOrTuple(type, indexes, dr, 0).Value);
|
||||
}, cmdType, cmdText, cmdParms);
|
||||
|
@ -14,13 +14,13 @@ namespace FreeSql.Internal.CommonProvider {
|
||||
var ret = new List<T>();
|
||||
var type = typeof(T);
|
||||
int[] indexes = null;
|
||||
var props = dicQueryTypeGetProperties.GetOrAdd(type, k => type.GetProperties().ToDictionary(a => a.Name, a => a, StringComparer.CurrentCultureIgnoreCase));
|
||||
var props = dicQueryTypeGetProperties.GetOrAdd(type, k => type.GetProperties());
|
||||
await ExecuteReaderAsync(dr => {
|
||||
if (indexes == null) {
|
||||
var idxs = new List<int>();
|
||||
var dic = new Dictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
|
||||
for (var a = 0; a < dr.FieldCount; a++)
|
||||
if (props.ContainsKey(dr.GetName(a))) idxs.Add(a);
|
||||
indexes = idxs.ToArray();
|
||||
dic.Add(dr.GetName(a), a);
|
||||
indexes = props.Select(a => dic.TryGetValue(a.Name, out var tryint) ? tryint : -1).ToArray();
|
||||
}
|
||||
ret.Add((T)Utils.ExecuteArrayRowReadClassOrTuple(type, indexes, dr, 0).Value);
|
||||
return Task.CompletedTask;
|
||||
|
@ -249,7 +249,7 @@ namespace FreeSql.Internal.CommonProvider {
|
||||
public Func<DbDataReader, T1> Read { get; set; }
|
||||
}
|
||||
protected GetAllFieldExpressionTreeInfo GetAllFieldExpressionTree() {
|
||||
return _dicGetAllFieldExpressionTree.GetOrAdd(string.Join("+", _tables.Select(a => $"{a.Table.DbName}-{a.Alias}")), s => {
|
||||
return _dicGetAllFieldExpressionTree.GetOrAdd(string.Join("+", _tables.Select(a => $"{a.Table.DbName}-{a.Alias}-{a.Type}")), s => {
|
||||
var tb1 = _tables.First().Table;
|
||||
var type = tb1.TypeLazy ?? tb1.Type;
|
||||
var props = tb1.Properties;
|
||||
|
Reference in New Issue
Block a user