My goal is to provide simple API to retrieve data from Payments
(~400 rows) table which consists 5 columns.
Payment: Id (int),
PaymentsNumber (tinyint),
Rate (decimal(18,2)),
ProductType (tinyint),
ClientClubType (tinyint).
Users can make posts request with with the request params of (should return ~12 rows):
PaymentsRequest
{
public int? PaymentsNumber { get; set; }
public byte? ProductType { get; set; }
public byte? ClientClubType { get; set; }
}
Using EF-Core:
services.AddDbContext<MyContext>(cfg => cfg.UseSqlServer(Configuration.GetConnectionString(...),optionsBuilder => optionsBuilder.CommandTimeout(60)));
public async Task<IEnumerable<Payments>> GetPaymentsAsync(PaymentsRequest request)
{
IQueryable<Payments> query = this._context.Set<Payments>();
query = query.Where(filter =>
(request.ClientClubType == null || filter.ClientClubType == request.ClientClubType) &&
(request.ProductType == null || filter.ProductType == request.ProductType) &&
(request.PaymentsNumber == null || filter.PaymentsNumber == request.PaymentsNumber));
return await query.ToListAsync();
}
On azure application insights I can see 2 consecutive logs, caused by the same exception:
The Log1 is (while there is no need to write here the log2):
Failed executing DbCommand (65,238ms) [Parameters=[@__request_ClientClubType_0='?' (Size = 1) (DbType = Byte), @__request_ProductType_1='?' (Size = 1) (DbType = Byte)], CommandType='Text', CommandTimeout='60']
SELECT [p].[Id], [p].[ClientClubType], [p].[PaymentsNumber], [p].[ProductType], [p].[Rate] FROM [Payments] AS [p] WHERE (([p].[ClientClubType] = @__request_ClientClubType_0) AND @__request_ClientClubType_0 IS NOT NULL) AND (([p].[ProductType] = @__request_ProductType_1) AND @__request_ProductType_1 IS NOT NULL)
My application is a .net core 3.0 application deployed on azure linux webapp.
The issue only occurs from production not every time and I can not reconstruct the issue from MSSMS. Any idea?
UPDATE:
After @panagiotis-kanavos commented, I've updated my code to:
services.AddDbContextPool<MyContext>(cfg => cfg.UseSqlServer(Configuration.GetConnectionString(...),optionsBuilder => optionsBuilder.CommandTimeout(60)));
public async Task<IEnumerable<Payments>> GetPaymentsAsync(PaymentsRequest request)
{
IQueryable<Payments> query = this._context.Payments;
query = query.Where(filter =>
(filter.ClientClubType == request.ClientClubType) &&
(filter.ProductType == request.ProductType) &&
(filter.PaymentsNumber == request.PaymentsNumber));
return await query.ToListAsync();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With