mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Add SimpleContext
This commit is contained in:
parent
643061af07
commit
cb6606bf42
@ -25,6 +25,26 @@ namespace OrmTest.Demo
|
||||
Tran();
|
||||
StoredProcedure();
|
||||
Enum();
|
||||
Simple();
|
||||
}
|
||||
|
||||
private static void Simple()
|
||||
{
|
||||
//SqlSugarClient
|
||||
var db = GetInstance();
|
||||
var student1 = db.Queryable<Student>().InSingle(1);
|
||||
|
||||
//get SimpleClient
|
||||
var sdb = db.SimpleClient;
|
||||
var student2 = sdb.GetById<Student>(1);
|
||||
sdb.DeleteById<Student>(1);
|
||||
sdb.Insert(new Student() { Name = "xx" });
|
||||
sdb.Update<Student>(it => new Student { Name = "newvalue" }, it => it.Id == 1);//only update name where id=1
|
||||
sdb.Update(new Student() { Name="newavalue" ,Id=1});//update all where id=1
|
||||
|
||||
//SimpleClient Get SqlSugarClient
|
||||
var student3=sdb.FullClient.Queryable<Student>().InSingle(1);
|
||||
|
||||
}
|
||||
|
||||
private static void StoredProcedure()
|
||||
|
@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("4.0.1")]
|
||||
[assembly: AssemblyFileVersion("4.0.1")]
|
||||
[assembly: AssemblyVersion("4.0.3")]
|
||||
[assembly: AssemblyFileVersion("4.0.3")]
|
||||
|
@ -16,6 +16,30 @@ namespace SqlSugar
|
||||
new KeyValuePair<string, CSharpDataType>("mediumint",CSharpDataType.@int),
|
||||
new KeyValuePair<string, CSharpDataType>("int",CSharpDataType.@int),
|
||||
new KeyValuePair<string, CSharpDataType>("integer",CSharpDataType.@int),
|
||||
new KeyValuePair<string, CSharpDataType>("bigint",CSharpDataType.@long),
|
||||
new KeyValuePair<string, CSharpDataType>("bit",CSharpDataType.@bool),
|
||||
new KeyValuePair<string, CSharpDataType>("real",CSharpDataType.@double),
|
||||
new KeyValuePair<string, CSharpDataType>("double",CSharpDataType.@double),
|
||||
new KeyValuePair<string, CSharpDataType>("float",CSharpDataType.@float),
|
||||
new KeyValuePair<string, CSharpDataType>("decimal",CSharpDataType.@decimal),
|
||||
new KeyValuePair<string, CSharpDataType>("numeric",CSharpDataType.@decimal),
|
||||
new KeyValuePair<string, CSharpDataType>("char",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("varchar",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("date",CSharpDataType.DateTime),
|
||||
new KeyValuePair<string, CSharpDataType>("time",CSharpDataType.DateTime),
|
||||
new KeyValuePair<string, CSharpDataType>("year",CSharpDataType.@int),
|
||||
new KeyValuePair<string, CSharpDataType>("timestamp",CSharpDataType.DateTime),
|
||||
new KeyValuePair<string, CSharpDataType>("datetime",CSharpDataType.DateTime),
|
||||
new KeyValuePair<string, CSharpDataType>("tinyblob",CSharpDataType.byteArray),
|
||||
new KeyValuePair<string, CSharpDataType>("blob",CSharpDataType.byteArray),
|
||||
new KeyValuePair<string, CSharpDataType>("varbinary",CSharpDataType.byteArray),
|
||||
new KeyValuePair<string, CSharpDataType>("binary",CSharpDataType.byteArray),
|
||||
new KeyValuePair<string, CSharpDataType>("multipoint",CSharpDataType.byteArray),
|
||||
new KeyValuePair<string, CSharpDataType>("geometry",CSharpDataType.byteArray),
|
||||
new KeyValuePair<string, CSharpDataType>("multilinestring",CSharpDataType.byteArray),
|
||||
new KeyValuePair<string, CSharpDataType>("polygon",CSharpDataType.byteArray),
|
||||
new KeyValuePair<string, CSharpDataType>("enum",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("text",CSharpDataType.@string),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,6 @@ namespace SqlSugar.Realization.MySql
|
||||
{
|
||||
public partial class DbType
|
||||
{
|
||||
public const string MySql = "MySql";
|
||||
// public const string MySql = "MySql";
|
||||
}
|
||||
}
|
||||
|
76
Src/Asp.Net/SqlSugar/SimpleClient.cs
Normal file
76
Src/Asp.Net/SqlSugar/SimpleClient.cs
Normal file
@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public partial class SimpleClient
|
||||
{
|
||||
protected SqlSugarClient Context { get; set; }
|
||||
public SqlSugarClient FullClient { get { return this.Context; } }
|
||||
|
||||
private SimpleClient()
|
||||
{
|
||||
|
||||
}
|
||||
public SimpleClient(SqlSugarClient context)
|
||||
{
|
||||
this.Context = context;
|
||||
}
|
||||
|
||||
public T GetById<T>(dynamic id) where T : class, new()
|
||||
{
|
||||
return Context.Queryable<T>().InSingle(id);
|
||||
}
|
||||
public List<T> GetList<T>() where T : class, new()
|
||||
{
|
||||
return Context.Queryable<T>().ToList();
|
||||
}
|
||||
public List<T> GetList<T>(Expression<Func<T, bool>> whereExpression) where T : class, new()
|
||||
{
|
||||
return Context.Queryable<T>().Where(whereExpression).ToList();
|
||||
}
|
||||
public bool Insert<T>(T insertObj) where T : class, new()
|
||||
{
|
||||
return this.Context.Insertable(insertObj).ExecuteCommand() > 0;
|
||||
}
|
||||
public int InsertReturnIdentity<T>(T insertObj) where T : class, new()
|
||||
{
|
||||
return this.Context.Insertable(insertObj).ExecuteReutrnIdentity();
|
||||
}
|
||||
public bool InsertRange<T>(T[] insertObjs) where T : class, new()
|
||||
{
|
||||
return this.Context.Insertable(insertObjs).ExecuteCommand() > 0;
|
||||
}
|
||||
public bool InsertRange<T>(List<T>[] insertObjs) where T : class, new()
|
||||
{
|
||||
return this.Context.Insertable(insertObjs).ExecuteCommand() > 0;
|
||||
}
|
||||
public bool Update<T>(T updateObj) where T : class, new()
|
||||
{
|
||||
return this.Context.Updateable(updateObj).ExecuteCommand() > 0;
|
||||
}
|
||||
public bool Update<T>(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression) where T : class, new()
|
||||
{
|
||||
return this.Context.Updateable<T>().UpdateColumns(columns).Where(whereExpression).ExecuteCommand() > 0;
|
||||
}
|
||||
public bool Delete<T>(T deleteObj) where T : class, new()
|
||||
{
|
||||
return this.Context.Deleteable<T>().Where(deleteObj).ExecuteCommand() > 0;
|
||||
}
|
||||
public bool Delete<T>(Expression<Func<T, bool>> whereExpression) where T : class, new()
|
||||
{
|
||||
return this.Context.Deleteable<T>().Where(whereExpression).ExecuteCommand() > 0;
|
||||
}
|
||||
public bool DeleteById<T>(dynamic id) where T : class, new()
|
||||
{
|
||||
return this.Context.Deleteable<T>().In(id).ExecuteCommand() > 0;
|
||||
}
|
||||
public bool DeleteByIds<T>(dynamic[] ids) where T : class, new()
|
||||
{
|
||||
return this.Context.Deleteable<T>().In(ids).ExecuteCommand() > 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -63,6 +63,7 @@
|
||||
<Compile Include="Abstract\FilterProvider\FilterProvider.cs" />
|
||||
<Compile Include="Abstract\InsertableProvider\InsertableProvider.cs" />
|
||||
<Compile Include="Abstract\DeleteProvider\DeleteableProvider.cs" />
|
||||
<Compile Include="SimpleClient.cs" />
|
||||
<Compile Include="Abstract\UpdateProvider\UpdateableProvider.cs" />
|
||||
<Compile Include="Entities\ModelContext.cs" />
|
||||
<Compile Include="Entities\SchemaInfo.cs" />
|
||||
|
@ -27,6 +27,7 @@ namespace SqlSugar
|
||||
protected IRewritableMethods _RewritableMethods;
|
||||
protected IDbMaintenance _DbMaintenance;
|
||||
protected QueryFilterProvider _QueryFilterProvider;
|
||||
protected SimpleClient _SimpleClient;
|
||||
#endregion
|
||||
|
||||
#region Init mppingInfo
|
||||
|
@ -206,7 +206,7 @@ namespace SqlSugar
|
||||
queryable.Where(joinExpression);
|
||||
return queryable;
|
||||
}
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Queryable<T, T2, T3, T4, T5, T6, T7>(Expression<Func<T, T2, T3, T4, T5, T6, T7,bool>> joinExpression) where T : class, new()
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Queryable<T, T2, T3, T4, T5, T6, T7>(Expression<Func<T, T2, T3, T4, T5, T6, T7, bool>> joinExpression) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6>();
|
||||
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7) };
|
||||
@ -331,7 +331,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Gobal Filter
|
||||
public QueryFilterProvider QueryFilter
|
||||
public virtual QueryFilterProvider QueryFilter
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -349,6 +349,19 @@ namespace SqlSugar
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SimpleClient
|
||||
public virtual SimpleClient SimpleClient
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_SimpleClient == null) {
|
||||
_SimpleClient = new SimpleClient(this);
|
||||
}
|
||||
return _SimpleClient;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Dispose OR Close
|
||||
public virtual void Close()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user