0
I upgraded EF Core to version 3.1.6 and am getting this exception when running a test.
The methods that cause this are these two:
public static IQueryable<CashoutRequest> WhereTransferOrInstitutionTransferStartDate
(
this IQueryable<CashoutRequest> cashoutRequests,
DateTime? date
)
{
if (date == null) return cashoutRequests;
var startDate = date.Value.Date;
return cashoutRequests.Where(cashoutRequest =>
cashoutRequest.Transfer.CreatedAt.Date >= startDate
||
cashoutRequest.InstitutionTransfer.CreatedAt.Date >= startDate
);
}
public static IQueryable<CashoutRequest> WhereTransferOrInstitutionTransferEndDate
(
this IQueryable<CashoutRequest> cashoutRequests,
DateTime? date
)
{
if (date == null) return cashoutRequests;
var endDate = date.Value.Date;
return cashoutRequests.Where(cashoutRequest =>
cashoutRequest.Transfer.CreatedAt.Date <= endDate
||
cashoutRequest.InstitutionTransfer.CreatedAt.Date <= endDate
);
}
The fields CreatedAt
are not nullables
, as if the Entity Framework Core made them nullables
in the execution?
Entities:
public class CashoutRequest
{
public long Id { get; set; }
public long? TransferId { get; set; }
public DateTime CreatedAt { get; set; } = DateTime.Now;
public DateTime? ReprovedAt { get; set; }
public DateTime? ApprovedAt { get; set; }
public DateTime? CanceledAt { get; set; }
public Transfer Transfer { get; set; }
public InstitutionTransfer InstitutionTransfer { get; set; }
}
public class Transfer
{
public long Id { get; set; }
public DateTime CreatedAt { get; set; } = DateTime.Now;
public DateTime? ApprovedAt { get; set; }
public DateTime? CanceledAt { get; set; }
public DateTime? ReprovedAt { get; set; }
}
public class InstitutionTransfer
{
public long Id { get; set; }
public DateTime CreatedAt { get; set; } = DateTime.Now;
public DateTime? ApprovedAt { get; set; }
public DateTime? CanceledAt { get; set; }
public DateTime? ReprovedAt { get; set; }
public long? CashoutRequestId { get; set; }
public CashoutRequest CashoutRequest { get; set; }
}
Was working and stopped working after the update? Post also the entity
CashoutRequest
,Transfer
andInstitutionTransfer
?– novic
Yes, it stopped working after the update
– Leandro Souza
@novic Entities are pretty big. I have tested now by removing the Date and it worked. Now I will search how to do to buy only the date
– Leandro Souza
Which bank is? and has the EF method (https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.ef.functions?view=efcore-5.0) and https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.dbfunctions?view=efcore-5.0
– novic
maybe: https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.sqlserverdbfunctionsextensions.datefromparts?view=efcore-5.0#Microsoft_EntityFrameworkCore_SqlServerDbFunctionsExtensions_DateFromParts_Microsoft_EntityFrameworkCore_DbFunctions_System_Int32_System_Int32_System_Int32_
– novic
@novic Is SQL Server
– Leandro Souza
Without the entities it’s hard to say!
– novic
@novic I put the entities
– Leandro Souza
must be the
nullable
of the vestments? make the changeDateTime date
forDateTime date
will work out then you have to use another strategy.– novic
because so
startDate
this different fromCreatedAt
, respectively Nullables and Datetime ... are different– novic
Another thing this method is not needed that way! see if you have a Linq Builder construct just copy the last change and move on ...
– novic
The problem is not the method parameter. I changed the Date property to Year and the exception was the same, changing only the message, referencing the Year property
– Leandro Souza
is yes guy are different, test with date without being nullable
– novic
but you noticed that
DateTime? date
and you’re using this variable for comparisons?– Leandro Angelo
@Leandroangelo But I pass the date to startDate by accessing Value, so it is a Datetime When I took the . Date the test passed
– Leandro Souza