mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-24 16:18:47 +08:00
Update mapper
This commit is contained in:
parent
919cd24cbd
commit
dc4a60acad
@ -12,12 +12,13 @@ namespace OrmTest
|
|||||||
{
|
{
|
||||||
var list4 = Db.Queryable<ABMapping>()
|
var list4 = Db.Queryable<ABMapping>()
|
||||||
.Mapper(it => it.A, it => it.AId)
|
.Mapper(it => it.A, it => it.AId)
|
||||||
.Mapper(it => it.B, it => it.BId)
|
.Where(it => it.A.Name == "a")
|
||||||
.Where(it=>it.A.Name=="A")
|
.ToList();
|
||||||
.Where(it=>it.B.Id==1)
|
|
||||||
.Select(it=>new {
|
|
||||||
id=it.B.Id
|
var list5 = Db.Queryable<ABMapping>()
|
||||||
})
|
.Mapper(it => it.A, it => it.AId, it => it.A.Id)
|
||||||
|
.Where(it => it.A.Name == "a")
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -116,6 +116,11 @@ namespace SqlSugar
|
|||||||
public ISugarQueryable<T> Mapper<TObject>(Expression<Func<T, TObject>> mapperObject, Expression<Func<T, object>> mainField, Expression<Func<T, object>> childField)
|
public ISugarQueryable<T> Mapper<TObject>(Expression<Func<T, TObject>> mapperObject, Expression<Func<T, object>> mainField, Expression<Func<T, object>> childField)
|
||||||
{
|
{
|
||||||
Check.Exception(mapperObject.ReturnType.Name == "IList`1", "Mapper no support IList , Use List<T>");
|
Check.Exception(mapperObject.ReturnType.Name == "IList`1", "Mapper no support IList , Use List<T>");
|
||||||
|
if (CallContext.MapperExpression.Value == null)
|
||||||
|
{
|
||||||
|
CallContext.MapperExpression.Value = new List<MapperExpression>();
|
||||||
|
}
|
||||||
|
CallContext.MapperExpression.Value.Add(new MapperExpression() { SqlBuilder = SqlBuilder, QueryBuilder = this.QueryBuilder, Type = MapperExpressionType.oneToOne, FillExpression = mapperObject, MappingField1Expression = mainField, MappingField2Expression=childField, Context = this.Context });
|
||||||
return _Mapper<TObject>(mapperObject, mainField, childField);
|
return _Mapper<TObject>(mapperObject, mainField, childField);
|
||||||
}
|
}
|
||||||
public ISugarQueryable<T> Mapper<TObject>(Expression<Func<T, List<TObject>>> mapperObject, Expression<Func<T, object>> mainField, Expression<Func<T, object>> childField)
|
public ISugarQueryable<T> Mapper<TObject>(Expression<Func<T, List<TObject>>> mapperObject, Expression<Func<T, object>> mainField, Expression<Func<T, object>> childField)
|
||||||
|
@ -54,7 +54,7 @@ namespace SqlSugar
|
|||||||
|
|
||||||
if (isExMapper)
|
if (isExMapper)
|
||||||
{
|
{
|
||||||
ExtMapper();
|
ExtMapper(fillInfo, mappingFild1Info, mappingFild1Info2, SelectInfo);
|
||||||
}
|
}
|
||||||
else if (isSameProperty)
|
else if (isSameProperty)
|
||||||
{
|
{
|
||||||
@ -189,9 +189,15 @@ namespace SqlSugar
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ExtMapper()
|
private void ExtMapper(MapperExpressionInfo fillInfo, MapperExpressionInfo mappingFild1Info, MapperExpressionInfo mappingFild1Info2, MapperExpressionInfo selectInfo)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
var tableName = sqlBuilder.GetTranslationTableName(fillInfo.EntityInfo.DbTableName);
|
||||||
|
var whereLeft = sqlBuilder.GetTranslationColumnName(mappingFild1Info2.FieldName);
|
||||||
|
var whereRight = sqlBuilder.GetTranslationColumnName(mappingFild1Info.FieldString);
|
||||||
|
this.sql = this.context.Queryable<object>()
|
||||||
|
.AS(tableName)
|
||||||
|
.Where(string.Format(" {0}={1} ", whereLeft, whereRight))
|
||||||
|
.Select(sqlBuilder.GetTranslationColumnName(selectInfo.FieldName)).ToSql().Key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapperSql GetSql()
|
public MapperSql GetSql()
|
||||||
|
Loading…
Reference in New Issue
Block a user