mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
- 修复 属性无set自动忽略的bug;
- 优化 ISelect`1.Include之后ToList参数includeNestedMembers默认为true;
This commit is contained in:
parent
415e09f0da
commit
915af57baa
@ -405,6 +405,10 @@ namespace FreeSql.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Test1()
|
public void Test1()
|
||||||
{
|
{
|
||||||
|
var testincludeMemberssql1 = g.sqlite.Select<TaskBuild>().Where(a => a.Templates.Title == "1").ToList();
|
||||||
|
var testincludeMemberssql2 = g.sqlite.Select<TaskBuild>().Include(a => a.Templates).ToList();
|
||||||
|
|
||||||
|
|
||||||
var floorSql1 = g.mysql.Select<TaskBuild>().Where(a => a.OptionsEntity04 / 10000 == 121212 / 10000).ToSql();
|
var floorSql1 = g.mysql.Select<TaskBuild>().Where(a => a.OptionsEntity04 / 10000 == 121212 / 10000).ToSql();
|
||||||
var floorSql2 = g.mysql.Select<TaskBuild>().Where(a => a.OptionsEntity04 / 10000.0 == 121212 / 10000).ToSql();
|
var floorSql2 = g.mysql.Select<TaskBuild>().Where(a => a.OptionsEntity04 / 10000.0 == 121212 / 10000).ToSql();
|
||||||
|
|
||||||
|
@ -472,12 +472,12 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
|
|
||||||
return ToListAfPrivateAsync(sql, af, otherData);
|
return ToListAfPrivateAsync(sql, af, otherData);
|
||||||
}
|
}
|
||||||
public List<T1> ToList(bool includeNestedMembers = false)
|
public virtual List<T1> ToList(bool includeNestedMembers = false)
|
||||||
{
|
{
|
||||||
if (_selectExpression != null) return this.InternalToList<T1>(_selectExpression);
|
if (_selectExpression != null) return this.InternalToList<T1>(_selectExpression);
|
||||||
return this.ToListPrivate(includeNestedMembers == false ? this.GetAllFieldExpressionTreeLevel2() : this.GetAllFieldExpressionTreeLevelAll(), null);
|
return this.ToListPrivate(includeNestedMembers == false ? this.GetAllFieldExpressionTreeLevel2() : this.GetAllFieldExpressionTreeLevelAll(), null);
|
||||||
}
|
}
|
||||||
public Task<List<T1>> ToListAsync(bool includeNestedMembers = false)
|
public virtual Task<List<T1>> ToListAsync(bool includeNestedMembers = false)
|
||||||
{
|
{
|
||||||
if (_selectExpression != null) return this.InternalToListAsync<T1>(_selectExpression);
|
if (_selectExpression != null) return this.InternalToListAsync<T1>(_selectExpression);
|
||||||
return this.ToListPrivateAsync(includeNestedMembers == false ? this.GetAllFieldExpressionTreeLevel2() : this.GetAllFieldExpressionTreeLevelAll(), null);
|
return this.ToListPrivateAsync(includeNestedMembers == false ? this.GetAllFieldExpressionTreeLevel2() : this.GetAllFieldExpressionTreeLevelAll(), null);
|
||||||
|
@ -384,6 +384,10 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
public TDto First<TDto>() => this.ToOne<TDto>();
|
public TDto First<TDto>() => this.ToOne<TDto>();
|
||||||
public Task<TDto> FirstAsync<TDto>() => this.ToOneAsync<TDto>();
|
public Task<TDto> FirstAsync<TDto>() => this.ToOneAsync<TDto>();
|
||||||
|
|
||||||
|
public override List<T1> ToList(bool includeNestedMembers = false) => base.ToList(_isIncluded || includeNestedMembers);
|
||||||
|
public override Task<List<T1>> ToListAsync(bool includeNestedMembers = false) => base.ToListAsync(_isIncluded || includeNestedMembers);
|
||||||
|
|
||||||
|
bool _isIncluded = false;
|
||||||
public ISelect<T1> Include<TNavigate>(Expression<Func<T1, TNavigate>> navigateSelector) where TNavigate : class
|
public ISelect<T1> Include<TNavigate>(Expression<Func<T1, TNavigate>> navigateSelector) where TNavigate : class
|
||||||
{
|
{
|
||||||
var expBody = navigateSelector?.Body;
|
var expBody = navigateSelector?.Body;
|
||||||
@ -391,6 +395,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
var tb = _commonUtils.GetTableByEntity(expBody.Type);
|
var tb = _commonUtils.GetTableByEntity(expBody.Type);
|
||||||
if (tb == null) throw new Exception("Include 参数类型错误");
|
if (tb == null) throw new Exception("Include 参数类型错误");
|
||||||
|
|
||||||
|
_isIncluded = true;
|
||||||
_commonExpression.ExpressionWhereLambda(_tables, Expression.MakeMemberAccess(expBody, tb.Properties[tb.ColumnsByCs.First().Value.CsName]), null, null);
|
_commonExpression.ExpressionWhereLambda(_tables, Expression.MakeMemberAccess(expBody, tb.Properties[tb.ColumnsByCs.First().Value.CsName]), null, null);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -76,6 +76,11 @@ namespace FreeSql.Internal
|
|||||||
var setMethod = trytb.Type.GetMethod($"set_{p.Name}");
|
var setMethod = trytb.Type.GetMethod($"set_{p.Name}");
|
||||||
var colattr = common.GetEntityColumnAttribute(entity, p);
|
var colattr = common.GetEntityColumnAttribute(entity, p);
|
||||||
var tp = common.CodeFirst.GetDbInfo(colattr?.MapType ?? p.PropertyType);
|
var tp = common.CodeFirst.GetDbInfo(colattr?.MapType ?? p.PropertyType);
|
||||||
|
if (setMethod == null) // 属性没有 set自动忽略
|
||||||
|
{
|
||||||
|
if (colattr == null) colattr = new ColumnAttribute { IsIgnore = true };
|
||||||
|
else colattr.IsIgnore = true;
|
||||||
|
}
|
||||||
if (tp == null && colattr?.IsIgnore != true)
|
if (tp == null && colattr?.IsIgnore != true)
|
||||||
{
|
{
|
||||||
if (common.CodeFirst.IsLazyLoading)
|
if (common.CodeFirst.IsLazyLoading)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user