Skip to content

Commit 255593a

Browse files
2881028810
authored andcommitted
- 增加 ISelect`1.WithSql("select * from user ...") 功能;
1 parent 113a827 commit 255593a

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

FreeSql.DbContext/FreeSql.DbContext.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FreeSql/FreeSql.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FreeSql/Interface/Curd/ISelect/ISelect1.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,5 +369,13 @@ public interface ISelect<T1> : ISelect0<ISelect<T1>, T1>, ILinqToSql<T1> where T
369369
/// <param name="then">即能 ThenInclude,还可以二次过滤(这个 EFCore 做不到?)</param>
370370
/// <returns></returns>
371371
ISelect<T1> IncludeMany<TNavigate>(Expression<Func<T1, IEnumerable<TNavigate>>> navigateSelector, Action<ISelect<TNavigate>> then = null) where TNavigate : class;
372+
373+
/// <summary>
374+
/// 实现 select .. from ( select ... from t ) a 这样的功能<para></para>
375+
/// 使用 AsTable 方法也可以达到效果
376+
/// </summary>
377+
/// <param name="sql">SQL语句</param>
378+
/// <returns></returns>
379+
ISelect<T1> WithSql(string sql);
372380
}
373381
}

FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,16 @@ public ISelect<T1> WhereCascade(Expression<Func<T1, bool>> exp)
329329
return this;
330330
}
331331

332+
public ISelect<T1> WithSql(string sql)
333+
{
334+
this.AsTable((type, old) =>
335+
{
336+
if (type == _tables.First().Table?.Type) return $"( {sql} )";
337+
return old;
338+
});
339+
return this;
340+
}
341+
332342
public bool Any(Expression<Func<T1, bool>> exp) => this.Where(exp).Any();
333343

334344
public TReturn ToOne<TReturn>(Expression<Func<T1, TReturn>> select) => this.Limit(1).ToList(select).FirstOrDefault();

0 commit comments

Comments
 (0)