mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 增加 ISelectGrouping First 方法;
This commit is contained in:
parent
4a4751708a
commit
df3073819d
Binary file not shown.
@ -569,6 +569,8 @@ namespace base_entity
|
||||
#endregion
|
||||
fsql.UseJsonMap();
|
||||
|
||||
fsql.Select<User1>().IncludeMany(a => a.Roles);
|
||||
|
||||
var displayNameTb = fsql.CodeFirst.GetTableByEntity(typeof(DeviceCodes));
|
||||
|
||||
var joinsql1 = fsql.Select<JoinTest01>()
|
||||
@ -598,7 +600,7 @@ namespace base_entity
|
||||
|
||||
Console.WriteLine(sw111);
|
||||
|
||||
var testsql01 = fsql.Select<User1>()
|
||||
var testsql01 = fsql.Select<User1>()
|
||||
//.GroupBy(a => new { a.Avatar, a.GroupId })
|
||||
//.Having(g => g.Sum(g.Value.Sort) > 0)
|
||||
.WithTempQuery(a => new
|
||||
@ -662,13 +664,13 @@ namespace base_entity
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Npgsql.NpgsqlConnection.GlobalTypeMapper.UseNetTopologySuite();
|
||||
var geo = new Point(10, 20);
|
||||
fsql.Select<City>()
|
||||
.Where(a => geo.Distance(a.Center) < 100).ToList();
|
||||
|
||||
|
||||
if (fsql.Ado.DataType == DataType.PostgreSQL)
|
||||
{
|
||||
Npgsql.NpgsqlConnection.GlobalTypeMapper.UseNetTopologySuite();
|
||||
var geo = new Point(10, 20);
|
||||
fsql.Select<City>()
|
||||
.Where(a => geo.Distance(a.Center) < 100).ToList();
|
||||
}
|
||||
|
||||
var items = new List<User1>();
|
||||
for (var a = 0; a < 3; a++) items.Add(new User1 { Id = Guid.NewGuid(), Avatar = $"avatar{a}" });
|
||||
@ -860,6 +862,15 @@ namespace base_entity
|
||||
list2 = userRepository.Select.Where(b => b.GroupId == a.Id).ToList(b => b.Nickname),
|
||||
});
|
||||
|
||||
var testsublist2 = fsql.Select<UserGroup>()
|
||||
.GroupBy(a => new { a.Id })
|
||||
.First(a => new
|
||||
{
|
||||
a.Id,
|
||||
list = userRepository.Select.Where(b => b.GroupId == a.Id).ToList(),
|
||||
list2 = userRepository.Select.Where(b => b.GroupId == a.Id).ToList(b => b.Nickname),
|
||||
});
|
||||
|
||||
|
||||
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||||
dic.Add("id", 1);
|
||||
@ -1985,7 +1996,7 @@ namespace base_entity
|
||||
public virtual string Code { get; set; }
|
||||
public virtual string Name { get; set; }
|
||||
}
|
||||
[Table(Name = "`FreeSqlTest`.`bdd_1`")]
|
||||
[Table(Name = "`bdd_1`")]
|
||||
class GoodsData : BaseDataEntity
|
||||
{
|
||||
public override Int32 CategoryId { get; set; }
|
||||
|
@ -16,6 +16,8 @@ namespace FreeSql
|
||||
Task<long> CountAsync(CancellationToken cancellationToken = default);
|
||||
Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TReturn>> select, CancellationToken cancellationToken = default);
|
||||
Task<Dictionary<TKey, TElement>> ToDictionaryAsync<TElement>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TElement>> elementSelector, CancellationToken cancellationToken = default);
|
||||
Task<TReturn> FirstAsync<TReturn>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TReturn>> select, CancellationToken cancellationToken = default);
|
||||
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
@ -54,6 +56,13 @@ namespace FreeSql
|
||||
/// <returns></returns>
|
||||
List<TReturn> ToList<TReturn>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TReturn>> select);
|
||||
Dictionary<TKey, TElement> ToDictionary<TElement>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TElement>> elementSelector);
|
||||
/// <summary>
|
||||
/// 执行SQL查询,返回指定字段的记录的第一条记录,记录不存在时返回 TReturn 默认值
|
||||
/// </summary>
|
||||
/// <typeparam name="TReturn"></typeparam>
|
||||
/// <param name="select"></param>
|
||||
/// <returns></returns>
|
||||
TReturn First<TReturn>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TReturn>> select);
|
||||
|
||||
/// <summary>
|
||||
/// 【linq to sql】专用方法,不建议直接使用
|
||||
|
@ -1154,6 +1154,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
var tbrefMid = _commonUtils.GetTableByEntity(tbref.RefMiddleEntityType);
|
||||
var tbrefMidName = _tableRules?.FirstOrDefault()?.Invoke(tbref.RefMiddleEntityType, tbrefMid.DbName) ?? tbrefMid.DbName;
|
||||
var sbJoin = new StringBuilder().Append($"{_commonUtils.QuoteSqlName(tbrefMidName)} midtb ON ");
|
||||
if (_orm.CodeFirst.IsAutoSyncStructure && tbrefMid.Type != typeof(object)) _orm.CodeFirst.SyncStructure(tbrefMid.Type, tbrefMidName);
|
||||
for (var z = 0; z < tbref.RefColumns.Count; z++)
|
||||
{
|
||||
if (z > 0) sbJoin.Append(" AND ");
|
||||
|
@ -329,6 +329,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
|
||||
public List<TReturn> Select<TReturn>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TReturn>> select) => ToList(select);
|
||||
public TReturn First<TReturn>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TReturn>> select) => ToList<TReturn>(select).FirstOrDefault();
|
||||
public List<TReturn> ToList<TReturn>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TReturn>> select)
|
||||
{
|
||||
_lambdaParameter = select?.Parameters[0];
|
||||
@ -344,6 +345,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
#else
|
||||
async public Task<long> CountAsync(CancellationToken cancellationToken = default) => _select._cancel?.Invoke() == true ? 0 : long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(_select._connection, _select._transaction, CommandType.Text, $"select count(1) from ({this.ToSql($"1{_comonExp._common.FieldAsAlias("as1")}")}) fta", _select._commandTimeout, _select._params.ToArray(), cancellationToken)), out var trylng) ? trylng : default(long);
|
||||
|
||||
async public Task<TReturn> FirstAsync<TReturn>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TReturn>> select, CancellationToken cancellationToken = default) => (await ToListAsync<TReturn>(select, cancellationToken)).FirstOrDefault();
|
||||
public Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TReturn>> select, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var map = new ReadAnonymousTypeInfo();
|
||||
|
Loading…
x
Reference in New Issue
Block a user