fix(sql): change query execution to use ToList before FirstOrDefault
- Change from FirstOrDefaultAsync to ToListAsync + FirstOrDefault - Ensures proper query execution for both EF6 (.NET Framework 4.8) and EF Core (.NET 8.0) - Prevents potential query execution issues - Add using System.Linq directive
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
#if NET48
|
||||
using System.Data.Entity;
|
||||
using System.Linq;
|
||||
#else
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
#endif
|
||||
@@ -8,6 +7,7 @@ using ECMJobRunner.Application.Common.Interfaces;
|
||||
using ECMJobRunner.Infrastructure.Data;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
|
||||
namespace ECMJobRunner.Infrastructure.Services
|
||||
{
|
||||
@@ -41,16 +41,16 @@ namespace ECMJobRunner.Infrastructure.Services
|
||||
// Entity Framework 6 implementation
|
||||
var result = await _context.Database
|
||||
.SqlQuery<TResult>(sql)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
return result;
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
return result.FirstOrDefault();
|
||||
#else
|
||||
// Entity Framework Core implementation
|
||||
var result = await _context.Database
|
||||
.SqlQueryRaw<TResult>(sql)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
return result;
|
||||
return result.FirstOrDefault();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user