HLCores.Extensions.Linq
1.0.1
dotnet add package HLCores.Extensions.Linq --version 1.0.1
NuGet\Install-Package HLCores.Extensions.Linq -Version 1.0.1
<PackageReference Include="HLCores.Extensions.Linq" Version="1.0.1" />
paket add HLCores.Extensions.Linq --version 1.0.1
#r "nuget: HLCores.Extensions.Linq, 1.0.1"
// Install HLCores.Extensions.Linq as a Cake Addin #addin nuget:?package=HLCores.Extensions.Linq&version=1.0.1 // Install HLCores.Extensions.Linq as a Cake Tool #tool nuget:?package=HLCores.Extensions.Linq&version=1.0.1
HLCores.Extensions.Linq
HLCores.Extensions.Linq is custom functions linq.
Features
- FullOuterJoin.
- FullOuterGroupJoin.
- IOrderedQueryable
<TSource>
SortByDescending<TSource>
(this IQueryable<TSource>
source, stringpropertyName). - IOrderedQueryable
<TSource>
SortBy<TSource>
(this IQueryable<TSource>
source, stringpropertyName). - IOrderedQueryable
<TSource>
SortBy<TSource>
(this IQueryable<TSource>
source, List<SortParam>
sortParams). - IOrderedEnumerable
<TSource>
SortBy<TSource>
(this IEnumerable<TSource>
source, stringpropertyName). - IOrderedEnumerable
<TSource>
SortByDescending<TSource>
(this IEnumerable<TSource>
source, stringpropertyName). - IOrderedEnumerable
<TSource>
SortBy<TSource>
(this IEnumerable<TSource>
source, List<SortParam>
sortParams).
Usage
1. FullOuterJoin & FullOuterGroupJoin
Joining is a term borrowed from relational database design:
- A join will repeat elements from
a
as many times as there are elements inb
with corresponding key (i.e.: nothing ifb
were empty). Database lingo calls thisinner join
. - An outer join includes elements from
a
for which no corresponding element exists inb
. (i.e.: even results ifb
were empty). This is usually referred to asleft join
. - A full outer join includes records from
a
as well asb
if no corresponding element exists in the other. (i.e. even results ifa
were empty)
Something not usually seen in RDBMS is a group join:
- A group join , does the same as described above, but instead of repeating elements from
a
for multiple correspondingb
, it groups the records with corresponding keys. This is often more convenient when you wish to enumerate through 'joined' records, based on a common key.
See also GroupJoin which contains some general background explanations as well.
Exam:
var result = tableA.FullOuterJoin(
tableB,
a => a.Id, // Key selector for TableA
b => b.ForeignKeyId, // Key selector for TableB
(a, b, key) => new // Result projection
{
TableA = a,
TableB = b,
Key = key
}
);
var result = tableA.FullOuterGroupJoin(
tableB,
a => a.Id, // Key selector for TableA
b => b.ForeignKeyId, // Key selector for TableB
(a, b, key) => new // Result projection
{
TableA = a,
TableB = b,
Key = key
},
default(TableA), // Default value for TableA
default(TableB) // Default value for TableB
);
2. SortBy
Sorts the elements of a sequence in ascending order according to a string key required must exist in TSource
Exam:
public async Task<PaginationUtility<DistrictDto>> GetDataPagination(PaginationParam pagination, DistrictParam param)
{
var predicate = PredicateBuilder.New<District>(true);
if (!string.IsNullOrWhiteSpace(param.Keyword))
{
string keyword = param.Keyword.ToLower();
predicate.And(x => x.Title.ToLower().Contains(keyword) || x.Code.ToLower().Contains(keyword));
}
if (param.ProvinceId is not null)
predicate.And(x => x.ProvinceId == param.ProvinceId);
var data = _context.District.Where(predicate)
.Include(x => x.Province)
.Map<DistrictDto>()
.SortBy("UpdateTime").AsNoTracking();
return await PaginationUtility<DistrictDto>.CreateAsync(data, pagination.PageNumber, pagination.PageSize);
}
3. SortByDescending
Sorts the elements of a sequence in descending order according to a string key required must exist in TSource.
Exam:
public async Task<PaginationUtility<DistrictDto>> GetDataPagination(PaginationParam pagination, DistrictParam param)
{
var predicate = PredicateBuilder.New<District>(true);
if (!string.IsNullOrWhiteSpace(param.Keyword))
{
string keyword = param.Keyword.ToLower();
predicate.And(x => x.Title.ToLower().Contains(keyword) || x.Code.ToLower().Contains(keyword));
}
if (param.ProvinceId is not null)
predicate.And(x => x.ProvinceId == param.ProvinceId);
var data = _context.District.Where(predicate)
.Include(x => x.Province)
.Map<DistrictDto>()
.SortByDescending("UpdateTime").AsNoTracking();
return await PaginationUtility<DistrictDto>.CreateAsync(data, pagination.PageNumber, pagination.PageSize);
}
4. SortBy (sort params)
Sorts the elements of a sequence in ascending/descending order according by list sort param.
Exam:
public async Task<PaginationUtility<DistrictDto>> GetDataPagination(PaginationParam pagination, DistrictParam param)
{
var predicate = PredicateBuilder.New<District>(true);
if (!string.IsNullOrWhiteSpace(param.Keyword))
{
string keyword = param.Keyword.ToLower();
predicate.And(x => x.Title.ToLower().Contains(keyword) || x.Code.ToLower().Contains(keyword));
}
if (param.ProvinceId is not null)
predicate.And(x => x.ProvinceId == param.ProvinceId);
var data = _context.District.Where(predicate)
.Include(x => x.Province)
.Map<DistrictDto>()
.SortBy(new List<SortParam>()
{
new() {
Direction = SortDirection.Ascending,
PropertyName = "ProvinceCode"
},
new() {
Direction = SortDirection.Descending,
PropertyName = "Code"
}
}).AsNoTracking();
return await PaginationUtility<DistrictDto>.CreateAsync(data, pagination.PageNumber, pagination.PageSize);
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.1 | 100 | 9/19/2024 |