mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-18 17:48:11 +08:00
-
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class EntityProvider
|
||||
{
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public EntityInfo GetEntityInfo<T>()where T:class,new()
|
||||
{
|
||||
string cacheKey = "GetEntityInfo";
|
||||
return CacheFactory.Func<EntityInfo>(cacheKey,
|
||||
(cm, key) =>
|
||||
{
|
||||
return cm[cacheKey];
|
||||
|
||||
}, (cm, key) =>
|
||||
{
|
||||
EntityInfo result = new EntityInfo();
|
||||
var type = typeof(T);
|
||||
result.Type = type;
|
||||
result.Type.GetProperties();
|
||||
result.Name =result.Type.Name;
|
||||
result.Columns = new List<EntityColumnInfo>();
|
||||
foreach (var item in result.Type.GetProperties())
|
||||
{
|
||||
EntityColumnInfo columns = new EntityColumnInfo();
|
||||
columns.ColumnName = item.Name;
|
||||
columns.PropertyInfo = item;
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -10,16 +10,15 @@ namespace SqlSugar
|
||||
public class InsertableProvider<T> : IInsertable<T> where T : class, new()
|
||||
{
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public bool IsMappingTable { get { return this.Context.MappingTables != null && this.Context.MappingTables.Any(); } }
|
||||
public bool IsMappingColumns { get { return this.Context.MappingColumns != null && this.Context.MappingColumns.Any(); } }
|
||||
public IDb Db { get { return Context.Database; } }
|
||||
public IDbBind Bind { get { return this.Db.DbBind; } }
|
||||
public ISqlBuilder SqlBuilder { get; set; }
|
||||
public InsertBuilder InsertBuilder
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.SqlBuilder.InsertBuilder;
|
||||
}
|
||||
}
|
||||
public InsertBuilder InsertBuilder { get { return this.InsertBuilder; } }
|
||||
public EntityInfo EntityInfo { get; set; }
|
||||
private List<string> IgnoreColumnList { get; set; }
|
||||
private List<string> InsertColumList { get; set; }
|
||||
public T[] InsertObjs { get; set; }
|
||||
public int ExecuteCommand()
|
||||
{
|
||||
return Db.ExecuteCommand(InsertBuilder.ToSqlString(), InsertBuilder.Parameters);
|
||||
@@ -40,27 +39,18 @@ namespace SqlSugar
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IInsertable<T> Insert(T InsertObj)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public IInsertable<T> InsertColumns(Expression<Func<T, object[]>> columns)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public IInsertable<T> InsertRange(List<T> InsertObjs)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public IInsertable<T> With(string lockString)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public IInsertable<T> Where(bool isInsertNull) {
|
||||
public IInsertable<T> Where(bool isInsertNull)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
22
SqlSugar/Entities/EntityColumnInfo.cs
Normal file
22
SqlSugar/Entities/EntityColumnInfo.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class EntityColumnInfo
|
||||
{
|
||||
public PropertyInfo PropertyInfo { get; set; }
|
||||
public string EntityName { get; set; }
|
||||
public string ColumnName { get; set; }
|
||||
public int Length { get; set; }
|
||||
public string ColumnDescription { get; set; }
|
||||
public string DefaultValue { get; set; }
|
||||
public bool IsNullable { get; set; }
|
||||
public bool IsIdentity { get; set; }
|
||||
public bool IsPrimarykey { get; set; }
|
||||
}
|
||||
}
|
16
SqlSugar/Entities/EntityInfo.cs
Normal file
16
SqlSugar/Entities/EntityInfo.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class EntityInfo
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public Type Type { get; set; }
|
||||
public List<EntityColumnInfo> Columns { get; set; }
|
||||
}
|
||||
}
|
@@ -12,9 +12,10 @@ namespace SqlSugar
|
||||
int ExecuteCommand();
|
||||
int ExecuteReutrnIdentity();
|
||||
IInsertable<T> With(string lockString);
|
||||
IInsertable<T> InsertColumns(Expression<Func<T,object []>> columns);
|
||||
IInsertable<T> InsertColumns(Expression<Func<T, object[]>> columns);
|
||||
IInsertable<T> IgnoreColumns(Expression<Func<T, object[]>> columns);
|
||||
IInsertable<T> Where(bool isInsertNull);
|
||||
KeyValuePair<string, List<SugarParameter>> ToSql();
|
||||
EntityInfo EntityInfo { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -53,8 +53,11 @@
|
||||
<Compile Include="Abstract\DbProvider\DbFirstProvider\DbFirstProvider.cs" />
|
||||
<Compile Include="Abstract\DbProvider\DbMaintenanceProvider\DbMaintenanceProvider.cs" />
|
||||
<Compile Include="Abstract\DbProvider\DbProvider\DbProvider.cs" />
|
||||
<Compile Include="Abstract\DbProvider\EntityProvider\EntityProvider.cs" />
|
||||
<Compile Include="Abstract\InsertableProvider\InsertableProvider.cs" />
|
||||
<Compile Include="Databases\SqlServer\Db\SqlBuilder\SqlServerInsertBuilder.cs" />
|
||||
<Compile Include="Entities\EntityColumnInfo.cs" />
|
||||
<Compile Include="Entities\EntityInfo.cs" />
|
||||
<Compile Include="Entities\Mapping\SugarMappingAttribute.cs" />
|
||||
<Compile Include="Abstract\QueryableProvider\QueryableAccessory.cs" />
|
||||
<Compile Include="Abstract\QueryableProvider\QueryableExtendsions.cs" />
|
||||
|
@@ -18,6 +18,7 @@ namespace SqlSugar
|
||||
public IgnoreComumnList IgnoreComumns = new IgnoreComumnList();
|
||||
|
||||
protected ISqlBuilder _SqlBuilder;
|
||||
protected EntityProvider _EntityProvider;
|
||||
protected IDb _Ado;
|
||||
protected ILambdaExpressions _LambdaExpressions;
|
||||
protected object _Sqlable;
|
||||
|
@@ -71,7 +71,7 @@ namespace SqlSugar
|
||||
|
||||
#endregion
|
||||
|
||||
#region properties
|
||||
#region ADO Method
|
||||
/// <summary>
|
||||
///Database operation
|
||||
/// </summary>
|
||||
@@ -90,7 +90,9 @@ namespace SqlSugar
|
||||
return _Ado;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Rewritable Methods
|
||||
/// <summary>
|
||||
/// Rewritable Methods
|
||||
/// </summary>
|
||||
@@ -108,7 +110,7 @@ namespace SqlSugar
|
||||
{
|
||||
base._RewritableMethods = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Queryable
|
||||
@@ -226,12 +228,14 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Insertable
|
||||
public virtual IInsertable<T> Insertable<T>(params T[] insertObj) where T : class, new()
|
||||
public virtual IInsertable<T> Insertable<T>(params T[] insertObjs) where T : class, new()
|
||||
{
|
||||
var reval = new InsertableProvider<T>();
|
||||
reval.Context = this;
|
||||
reval.EntityInfo = this.EntityProvider.GetEntityInfo<T>();
|
||||
var sqlBuilder = InstanceFactory.GetSqlbuilder(base.CurrentConnectionConfig); ;
|
||||
reval.SqlBuilder = sqlBuilder;
|
||||
reval.InsertObjs = insertObjs;
|
||||
reval.SqlBuilder.InsertBuilder = InstanceFactory.GetInsertBuilder(base.CurrentConnectionConfig);
|
||||
reval.SqlBuilder.InsertBuilder.Builder = sqlBuilder;
|
||||
reval.SqlBuilder.Context = reval.SqlBuilder.QueryBuilder.Context = this;
|
||||
@@ -260,6 +264,24 @@ namespace SqlSugar
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Entity Methods
|
||||
public virtual EntityProvider EntityProvider
|
||||
{
|
||||
get
|
||||
{
|
||||
if (base._EntityProvider == null)
|
||||
{
|
||||
base._EntityProvider = new EntityProvider();
|
||||
}
|
||||
return _EntityProvider;
|
||||
}
|
||||
set
|
||||
{
|
||||
base._EntityProvider = value;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Dispose OR Close
|
||||
public virtual void Close()
|
||||
{
|
||||
|
Reference in New Issue
Block a user