mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-07 21:58:06 -05:00
EF Core LINQ Query Fails: DateTime.UtcNow - TimeSpan Cannot Be Translated
An unhandled exception occurs when running a LINQ query that includes DateTime.UtcNow - TimeSpan as a condition in Where(). EF Core cannot translate this expression into SQL.
This commit is contained in:
parent
c2cce14ad3
commit
3364183846
@ -198,10 +198,14 @@ namespace SharedLibraryCore.Services
|
|||||||
{
|
{
|
||||||
await using var context = _contextFactory.CreateContext(false);
|
await using var context = _contextFactory.CreateContext(false);
|
||||||
|
|
||||||
var recentlyUsedIps = await context.Aliases.Where(alias => alias.LinkId == linkId)
|
var cutoffDate = DateTime.UtcNow - _appConfig.RecentAliasIpLinkTimeLimit;
|
||||||
|
|
||||||
|
var recentlyUsedIps = await context.Aliases
|
||||||
|
.Where(alias => alias.LinkId == linkId)
|
||||||
.Where(alias => alias.IPAddress != null)
|
.Where(alias => alias.IPAddress != null)
|
||||||
.Where(alias => alias.DateAdded >= DateTime.UtcNow - _appConfig.RecentAliasIpLinkTimeLimit)
|
.Where(alias => alias.DateAdded >= cutoffDate)
|
||||||
.Select(alias => alias.IPAddress).ToListAsync();
|
.Select(alias => alias.IPAddress)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
if (!recentlyUsedIps.Any())
|
if (!recentlyUsedIps.Any())
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user