mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-18 17:48:11 +08:00
-
This commit is contained in:
@@ -30,6 +30,7 @@ namespace OrmTest.UnitTest
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
//var list = db.Queryable<Student>()
|
||||
|
||||
// .Where(st => st.Id > 0)
|
||||
// .Select(it => new ViewModelStudent { Name = it.Name }).ToList();
|
||||
//var list2 = db.Queryable<Student>()
|
||||
@@ -38,9 +39,11 @@ namespace OrmTest.UnitTest
|
||||
var list = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||
JoinType.Left,st.SchoolId==sc.Id
|
||||
}).Where(st => st.Id > 0).Select<Student>("*").ToList();
|
||||
var list3 = db.Queryable<Student>()
|
||||
.Where(st => st.Id > 0)
|
||||
.Select(it => new ViewModelStudent2 { Student = it }).ToList();
|
||||
|
||||
//var list3 = db.Queryable("Student","st")
|
||||
// .AddJoinInfo("Shool","sh", "sh.id=st.shoolid")
|
||||
// .Where(st => st.Id > 0)
|
||||
// .Select(st => new ViewModelStudent2 { Student = st }).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -38,8 +38,9 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISugarQueryable<T> AddJoinInfo(string tableName, string shortName, string Joinwhere, JoinType type)
|
||||
public ISugarQueryable<T> AddJoinInfo(string tableName, string shortName, string joinWhere, JoinType type = JoinType.Left)
|
||||
{
|
||||
|
||||
SqlBuilder.LambadaQueryBuilder.JoinIndex = +1;
|
||||
SqlBuilder.LambadaQueryBuilder.JoinQueryInfos
|
||||
.Add(new JoinQueryInfo()
|
||||
@@ -47,7 +48,8 @@ namespace SqlSugar
|
||||
JoinIndex = SqlBuilder.LambadaQueryBuilder.JoinIndex,
|
||||
TableName = tableName,
|
||||
ShortName = shortName,
|
||||
JoinType = type
|
||||
JoinType = type,
|
||||
JoinWhere = joinWhere
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
@@ -27,8 +27,7 @@ namespace SqlSugar
|
||||
public string OrderByValue { get; set; }
|
||||
public object SelectValue { get; set; }
|
||||
public string SelectCacheKey { get; set; }
|
||||
public Type EntityType { get; set; }
|
||||
public string EntityName { get { return this.EntityType.Name; } }
|
||||
public string EntityName { get; set; }
|
||||
public string TableWithString { get; set; }
|
||||
public string GroupByValue { get; set; }
|
||||
public int WhereIndex { get; set; }
|
||||
@@ -53,9 +52,17 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
return Builder.GetTranslationTableName(EntityType.Name);
|
||||
var result= Builder.GetTranslationTableName(EntityName)+TableWithString;
|
||||
if (this.TableShortName.IsValuable())
|
||||
{
|
||||
result += " " + TableShortName;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string TableShortName { get; set; }
|
||||
|
||||
public virtual string GetSelectValue
|
||||
{
|
||||
get
|
||||
@@ -148,7 +155,7 @@ namespace SqlSugar
|
||||
this.JoinTemplate,
|
||||
joinInfo.JoinIndex == 1 ? (joinInfo.PreShortName + " " + joinInfo.JoinType.ToString() + " ") : (joinInfo.JoinType.ToString() + " JOIN "),
|
||||
joinInfo.TableName,
|
||||
joinInfo.ShortName + " " + TableWithString,
|
||||
joinInfo.ShortName + " " + joinInfo.TableWithString,
|
||||
joinInfo.JoinWhere);
|
||||
}
|
||||
public virtual List<string> WhereInfos
|
||||
|
6
SqlSugar/DetaultT.cs
Normal file
6
SqlSugar/DetaultT.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class DetaultT
|
||||
{
|
||||
}
|
||||
}
|
@@ -8,7 +8,6 @@ namespace SqlSugar
|
||||
public class JoinQueryInfo
|
||||
{
|
||||
public JoinType JoinType{ get; set; }
|
||||
public string PreShortName { get; set; }
|
||||
public string TableName { get; set; }
|
||||
public string ShortName { get; set; }
|
||||
public int JoinIndex { get; set; }
|
||||
|
@@ -87,10 +87,8 @@ namespace SqlSugar
|
||||
}
|
||||
else if (item.Type.IsClass())
|
||||
{
|
||||
StringBuilder sb=new StringBuilder();
|
||||
string prefix = Context.IsJoin ? memberName : "";
|
||||
var listProperties = item.Type.GetProperties().Cast<PropertyInfo>().ToList();
|
||||
base.Context.Result.Append(sb.ToString());
|
||||
foreach (var property in listProperties)
|
||||
{
|
||||
if (property.PropertyType.IsClass())
|
||||
@@ -102,11 +100,11 @@ namespace SqlSugar
|
||||
var columnName = property.Name;
|
||||
if (Context.IsJoin)
|
||||
{
|
||||
// Context.GetAsString(prefix,item,)
|
||||
base.Context.Result.Append(Context.GetAsString(property.Name, columnName,""));
|
||||
}
|
||||
else
|
||||
{
|
||||
Context.GetAsString(columnName, columnName);
|
||||
base.Context.Result.Append(Context.GetAsString(property.Name, columnName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ namespace SqlSugar
|
||||
|
||||
ISugarQueryable<T> AddParameters(object pars);
|
||||
ISugarQueryable<T> AddParameters(SugarParameter[] pars);
|
||||
ISugarQueryable<T> AddJoinInfo(string tableName, string shortName, string Joinwhere, JoinType types);
|
||||
ISugarQueryable<T> AddJoinInfo(string tableName, string shortName, string joinWhere, JoinType type=JoinType.Left);
|
||||
|
||||
ISugarQueryable<T> Where(Expression<Func<T, bool>> expression);
|
||||
ISugarQueryable<T> Where(string whereString, object whereObj = null);
|
||||
|
@@ -86,6 +86,7 @@
|
||||
<Compile Include="Databases\SqlServer\Db\SqlServerDb.cs" />
|
||||
<Compile Include="Databases\SqlServer\Queryable\SqlServerQueryable.cs" />
|
||||
<Compile Include="Databases\SqlServer\Sqlable\SqlServerSqlable.cs" />
|
||||
<Compile Include="DetaultT.cs" />
|
||||
<Compile Include="Entities\ConnectionConfig.cs" />
|
||||
<Compile Include="Entities\DbColumnInfo.cs" />
|
||||
<Compile Include="Entities\DbTableInfo.cs" />
|
||||
|
@@ -100,7 +100,7 @@ namespace SqlSugar
|
||||
});
|
||||
}
|
||||
|
||||
protected List<JoinQueryInfo> GetJoinInfos(Expression joinExpression, SqlSugarClient context, params Type[] entityTypeArray)
|
||||
protected List<JoinQueryInfo> GetJoinInfos(Expression joinExpression, SqlSugarClient context,ref string shortName, params Type[] entityTypeArray)
|
||||
{
|
||||
List<JoinQueryInfo> reval = new List<JoinQueryInfo>();
|
||||
var lambdaParameters = ((LambdaExpression)joinExpression).Parameters.ToList();
|
||||
@@ -129,8 +129,8 @@ namespace SqlSugar
|
||||
if (isFirst)
|
||||
{
|
||||
var firstItem = lambdaParameters.First();
|
||||
joinInfo.PreShortName = firstItem.Name;
|
||||
lambdaParameters.Remove(firstItem);
|
||||
shortName = firstItem.Name;
|
||||
}
|
||||
var joinString = joinArray[i * 2 - 2];
|
||||
joinInfo.ShortName = lambdaParameters[i-1].Name;
|
||||
|
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Runtime.Remoting.Contexts;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace SqlSugar
|
||||
@@ -113,18 +114,40 @@ namespace SqlSugar
|
||||
{
|
||||
var reval = InstanceFactory.GetQueryable<T>(base.CurrentConnectionConfig);
|
||||
reval.Context = this;
|
||||
var SqlBuilder = InstanceFactory.GetSqlbuilder(base.CurrentConnectionConfig); ;
|
||||
reval.SqlBuilder = SqlBuilder;
|
||||
var sqlBuilder = InstanceFactory.GetSqlbuilder(base.CurrentConnectionConfig); ;
|
||||
reval.SqlBuilder = sqlBuilder;
|
||||
reval.SqlBuilder.LambadaQueryBuilder = InstanceFactory.GetLambadaQueryBuilder(base.CurrentConnectionConfig);
|
||||
reval.SqlBuilder.LambadaQueryBuilder.Builder = SqlBuilder;
|
||||
reval.SqlBuilder.LambadaQueryBuilder.Builder = sqlBuilder;
|
||||
reval.SqlBuilder.Context = reval.SqlBuilder.LambadaQueryBuilder.Context = this;
|
||||
reval.SqlBuilder.LambadaQueryBuilder.EntityType = typeof(T);
|
||||
reval.SqlBuilder.LambadaQueryBuilder.EntityName = typeof(T).Name;
|
||||
return reval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lambda Query operation
|
||||
/// </summary>
|
||||
public virtual ISugarQueryable<DetaultT> Queryable(string tableName,string shortName)
|
||||
{
|
||||
var queryable = Queryable<DetaultT>();
|
||||
queryable.SqlBuilder.LambadaQueryBuilder.TableShortName = shortName;
|
||||
return queryable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lambda Query operation
|
||||
/// </summary>
|
||||
public virtual ISugarQueryable<T> Queryable<T>(string shortName) where T : class, new()
|
||||
{
|
||||
var queryable = Queryable<T>();
|
||||
queryable.SqlBuilder.LambadaQueryBuilder.TableShortName = shortName;
|
||||
return queryable;
|
||||
}
|
||||
public virtual ISugarQueryable<T> Queryable<T, T2>(Expression<Func<T, T2, object[]>> joinExpression) where T : class, new()
|
||||
{
|
||||
var queryable = Queryable<T>();
|
||||
queryable.SqlBuilder.LambadaQueryBuilder.JoinQueryInfos = base.GetJoinInfos(joinExpression, this, typeof(T2));
|
||||
string shortName = string.Empty;
|
||||
queryable.SqlBuilder.LambadaQueryBuilder.JoinQueryInfos = base.GetJoinInfos(joinExpression, this,ref shortName, typeof(T2));
|
||||
queryable.SqlBuilder.LambadaQueryBuilder.TableShortName=shortName;
|
||||
return queryable;
|
||||
}
|
||||
public virtual ISugarQueryable<T> Queryable<T, T2, T3>(Func<T, T2, T3, object[]> joinExpression) where T : class, new()
|
||||
|
Reference in New Issue
Block a user