Code optimization

This commit is contained in:
sunkaixuan
2017-08-25 21:50:35 +08:00
parent 372b5fef78
commit 4d2af78259
5 changed files with 22 additions and 36 deletions

View File

@@ -48,7 +48,7 @@ namespace SqlSugar
}
public virtual void InitTables(string entitiesNamespace)
{
var types = ReflectionCore.Load(entitiesNamespace).GetTypes();
var types = Assembly.Load(entitiesNamespace).GetTypes();
InitTables(types);
}
public virtual void InitTables(params string[] entitiesNamespaces)

View File

@@ -82,36 +82,4 @@ namespace SqlSugar
return method.ReflectedType;
}
}
public static class AdoCore
{
public static List<DbColumnInfo> GetColumnInfosByTableName(string tableName, DbDataReader dataReader)
{
List<DbColumnInfo> result = new List<DbColumnInfo>();
var schemaTable = dataReader.GetSchemaTable();
foreach (DataRow row in schemaTable.Rows)
{
DbColumnInfo column = new DbColumnInfo()
{
TableName = tableName,
DataType = row["DataTypeName"].ToString().Trim(),
IsNullable = (bool)row["AllowDBNull"],
IsIdentity = (bool)row["IsAutoIncrement"],
ColumnDescription = null,
DbColumnName = row["ColumnName"].ToString(),
DefaultValue = row["defaultValue"].ToString(),
IsPrimarykey = (bool)row["IsKey"],
Length = Convert.ToInt32(row["ColumnSize"])
};
result.Add(column);
}
return result;
}
}
public static class ReflectionCore
{
public static Assembly Load(string name)
{
return Assembly.Load(name);
}
}
}

View File

@@ -8,7 +8,7 @@ namespace SqlSugar
{
public class InstanceFactory
{
static Assembly assembly = ReflectionCore.Load(PubConst.AssemblyName);
static Assembly assembly = Assembly.Load(PubConst.AssemblyName);
static Dictionary<string, Type> typeCache = new Dictionary<string, Type>();
#region Queryable

View File

@@ -181,7 +181,25 @@ namespace SqlSugar
using (DbDataReader reader = (SQLiteDataReader)this.Context.Ado.GetDataReader(sql))
{
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog;
return AdoCore.GetColumnInfosByTableName(tableName, reader);
List<DbColumnInfo> result = new List<DbColumnInfo>();
var schemaTable = reader.GetSchemaTable();
foreach (DataRow row in schemaTable.Rows)
{
DbColumnInfo column = new DbColumnInfo()
{
TableName = tableName,
DataType = row["DataTypeName"].ToString().Trim(),
IsNullable = (bool)row["AllowDBNull"],
IsIdentity = (bool)row["IsAutoIncrement"],
ColumnDescription = null,
DbColumnName = row["ColumnName"].ToString(),
DefaultValue = row["defaultValue"].ToString(),
IsPrimarykey = (bool)row["IsKey"],
Length = Convert.ToInt32(row["ColumnSize"])
};
result.Add(column);
}
return result;
}
});

View File

@@ -71,7 +71,7 @@
<Compile Include="Abstract\FilterProvider\FilterProvider.cs" />
<Compile Include="Abstract\InsertableProvider\InsertableProvider.cs" />
<Compile Include="Abstract\DeleteProvider\DeleteableProvider.cs" />
<Compile Include="CompatibleNetCore\CompatibleExtensions.cs" />
<Compile Include="Common\ReflectionExtensions.cs" />
<Compile Include="Realization\MySql\CodeFirst\MySqlCodeFirst.cs" />
<Compile Include="Realization\MySql\DbFirst\MySqlDbFirst.cs" />
<Compile Include="Realization\MySql\DbMaintenance\MySqlDbMaintenance.cs" />