Skip to content

Commit

Permalink
- 修复 UseGenerateCommandParameterWithLambda(true) 时子语句的参数没整合到主语句;#231
Browse files Browse the repository at this point in the history
- 增加 ISelect.RawJoin 方法以便实现 Outer Apply 查询;#200
  • Loading branch information
28810 authored and 28810 committed Mar 12, 2020
1 parent e132133 commit c468c65
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 55 deletions.
5 changes: 5 additions & 0 deletions FreeSql.Tests/FreeSql.Tests/UnitTest3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public class EdiItem
[Fact]
public void Test03()
{
var itemId = 1;
var edi = g.sqlite.Select<Edi>()
.Where(a => g.sqlite.Select<EdiItem>().Where(b => b.Id == itemId).Any())
.First(a => a); //#231

var lksdjkg1 = g.sqlite.Select<Edi>()
.AsQueryable().Where(a => a.Id > 0).ToList();

Expand Down
2 changes: 1 addition & 1 deletion FreeSql.Tests/FreeSql.Tests/g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class g
// return conn;
//})
.UseAutoSyncStructure(true)
//.UseGenerateCommandParameterWithLambda(true)
.UseGenerateCommandParameterWithLambda(true)
.UseLazyLoading(true)
.UseMonitorCommand(
cmd => Trace.WriteLine("\r\n线程" + Thread.CurrentThread.ManagedThreadId + ": " + cmd.CommandText) //监听SQL命令对象,在执行前
Expand Down
88 changes: 42 additions & 46 deletions FreeSql/FreeSql.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions FreeSql/Interface/Curd/ISelect/ISelect0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ public partial interface ISelect0<TSelect, T1> where T1 : class
/// <param name="parms">参数</param>
/// <returns></returns>
TSelect RightJoin(string sql, object parms = null);
/// <summary>
/// 在 JOIN 位置插入 SQL 内容<para></para>
/// 如:.RawJoin("OUTER APPLY ( select id from t2 ) b")
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
TSelect RawJoin(string sql);

/// <summary>
/// 原生sql语法条件,Where("id = ?id", new { id = 1 })
Expand Down
2 changes: 2 additions & 0 deletions FreeSql/Internal/CommonExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,8 @@ public string ExpressionLambdaToSql(Expression exp, ExpTSC tsc)
if (fsqlType == null) break;
if (exp3.Method.Name != "ToList")
fsqlType.GetField("_limit", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(fsql, 1);
if (tsc.dbParams != null)
fsqlType.GetField("_params", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(fsql, tsc.dbParams);
fsqltables = fsqlType.GetField("_tables", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(fsql) as List<SelectTableInfo>;
//fsqltables[0].Alias = $"{tsc._tables[0].Alias}_{fsqltables[0].Alias}";
if (fsqltables != tsc._tables)
Expand Down
21 changes: 13 additions & 8 deletions FreeSql/Internal/CommonProvider/SelectProvider/Select0Provider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,19 @@ public TSelect LeftJoin(string sql, object parms = null)
if (parms != null) _params.AddRange(_commonUtils.GetDbParamtersByObject(sql, parms));
return this as TSelect;
}
public TSelect RightJoin(string sql, object parms = null)
{
if (string.IsNullOrEmpty(sql)) return this as TSelect;
_join.Append(" \r\nRIGHT JOIN ").Append(sql);
if (parms != null) _params.AddRange(_commonUtils.GetDbParamtersByObject(sql, parms));
return this as TSelect;
}
public TSelect RawJoin(string sql)
{
if (string.IsNullOrEmpty(sql)) return this as TSelect;
_join.Append(" \r\n").Append(sql);
return this as TSelect;
}

public TSelect Limit(int limit)
{
Expand Down Expand Up @@ -273,14 +286,6 @@ public TSelect Page(int pageNumber, int pageSize)
return this.Limit(pageSize) as TSelect;
}

public TSelect RightJoin(string sql, object parms = null)
{
if (string.IsNullOrEmpty(sql)) return this as TSelect;
_join.Append(" \r\nRIGHT JOIN ").Append(sql);
if (parms != null) _params.AddRange(_commonUtils.GetDbParamtersByObject(sql, parms));
return this as TSelect;
}

public TSelect Skip(int offset)
{
_skip = offset;
Expand Down

0 comments on commit c468c65

Please sign in to comment.