@Jesús Torres, Welcome to Microsoft Q&A,
First of all, I will explain why test could be passed but use a case throw the related exceptions.
Please read the Microsoft Learning EF Core In-Memory Database Provider, which has the following mention:
The In-Memory provider was not designed for use outside of testing environments and should never be used as such.
Therefore, you may not get it worked in real cases.
Now I will explain why these two exceptions will throw.
EXCEPTION:
The client projection contains a reference to a constant expression of 'Barcelo.Integrator.Booking.Repository.HotelRepository' through the instance method 'GetTaxType'.
This could potentially cause a memory leak; consider making the method static so that it does not capture constant in the instance.
Based on my test, I reproduced this problem. According to my research, the possible reason may be that If you include an instance method in an IQueryable, it will be cached and the method will not be released even after your context has been processed. If you want to learn more about it, you could refer to this answer.
Translation of method 'System.Extensions.ToDate' failed.
Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'.
EF Core doesn't know how to translate ToDate method into a SQL command. Here you could try the following code to replace ToDate method:
.Where(c => c.CodHotel == hotelCode
&& DateTime.ParseExact(c.FechaHasta, Common.Constants.FORMATDATETIME_YYYYMMDD, System.Globalization.CultureInfo.InvariantCulture) >= DateTime.ParseExact(checkOut, Common.Constants.FORMATDATETIME_YYYYMMDD, System.Globalization.CultureInfo.InvariantCulture))
.Select(s => new Cancelation()
{
Release = Release
})
Hope my explanation could be helpful.
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.