Aslan Akbey
Aslan Akbey
CC#
Created by UltraWelfare on 1/19/2024 in #help
How to structure query functions in services
I misunderstood the problem. Sorry, I just realized. I think you want to call the same method in two different ways in two different services in the Service Layer, is that correct?
22 replies
CC#
Created by UltraWelfare on 1/19/2024 in #help
How to structure query functions in services
I think factory is more performant
22 replies
CC#
Created by UltraWelfare on 1/19/2024 in #help
How to structure query functions in services
sorry, I misunderstood the question
22 replies
CC#
Created by UltraWelfare on 1/19/2024 in #help
How to structure query functions in services
The only problem is that you cannot use it in Dapper or a similar orm other than EF Core.
22 replies
CC#
Created by UltraWelfare on 1/19/2024 in #help
How to structure query functions in services
What do you see as a problem?
22 replies
CC#
Created by UltraWelfare on 1/19/2024 in #help
How to structure query functions in services
You should define this in the data access or persistence layer and use it only in the service layer.
22 replies
CC#
Created by UltraWelfare on 1/19/2024 in #help
How to structure query functions in services
public async Task<IQueryable<T>> GetListAsync(Expression<Func<T, bool>>? predicate = null, Func<IQueryable<T>, IOrderedQueryable<T>>? orderBy = null, Func<IQueryable<T>, IIncludableQueryable<T, object>>? include = null, bool enableTracking = true, CancellationToken cancellationToken = default)
{
IQueryable<T> queryable = Table.AsQueryable();
if (!enableTracking) queryable = queryable.AsNoTracking();
if (include != null) queryable = include(queryable);
if (predicate != null) queryable = queryable.Where(predicate);
if (orderBy != null)
return await Task.FromResult(orderBy(queryable));
return await Task.FromResult(queryable);
}
public async Task<IQueryable<T>> GetListAsync(Expression<Func<T, bool>>? predicate = null, Func<IQueryable<T>, IOrderedQueryable<T>>? orderBy = null, Func<IQueryable<T>, IIncludableQueryable<T, object>>? include = null, bool enableTracking = true, CancellationToken cancellationToken = default)
{
IQueryable<T> queryable = Table.AsQueryable();
if (!enableTracking) queryable = queryable.AsNoTracking();
if (include != null) queryable = include(queryable);
if (predicate != null) queryable = queryable.Where(predicate);
if (orderBy != null)
return await Task.FromResult(orderBy(queryable));
return await Task.FromResult(queryable);
}
22 replies
CC#
Created by UltraWelfare on 1/19/2024 in #help
How to structure query functions in services
public async Task<IQueryable<T>> GetListAsync(Expression<Func<T, bool>>? predicate = null, Func<IQueryable<T>, IOrderedQueryable<T>>? orderBy = null, Func<IQueryable<T>, IIncludableQueryable<T, object>>? include = null, bool enableTracking = true, CancellationToken cancellationToken = default) { IQueryable<T> queryable = Table.AsQueryable(); if (!enableTracking) queryable = queryable.AsNoTracking(); if (include != null) queryable = include(queryable); if (predicate != null) queryable = queryable.Where(predicate); if (orderBy != null) return await Task.FromResult(orderBy(queryable)); return await Task.FromResult(queryable); }
22 replies
CC#
Created by UltraWelfare on 1/19/2024 in #help
How to structure query functions in services
Task<IQueryable<T>> GetListAsync(Expression<Func<T, bool>>? predicate = null,
Func<IQueryable<T>, IOrderedQueryable<T>>? orderBy = null,
Func<IQueryable<T>, IIncludableQueryable<T, object>>? include = null,
bool enableTracking = true,
CancellationToken cancellationToken = default);
Task<IQueryable<T>> GetListAsync(Expression<Func<T, bool>>? predicate = null,
Func<IQueryable<T>, IOrderedQueryable<T>>? orderBy = null,
Func<IQueryable<T>, IIncludableQueryable<T, object>>? include = null,
bool enableTracking = true,
CancellationToken cancellationToken = default);
22 replies
CC#
Created by UltraWelfare on 1/19/2024 in #help
How to structure query functions in services
but you can use it only with ef core 🙂
22 replies
CC#
Created by UltraWelfare on 1/19/2024 in #help
How to structure query functions in services
22 replies