Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Migrate EF query from 2.2 to 3.1

$
0
0

Hi

I'm trying to migrate my project from .net core 2.2 to 3.1,the following code wored fine but now gives that error:

System.InvalidOperationException: The LINQ expression 'DbSet<HT_REZERVARI>
.Where(h => h.DATAI.AddDays((double)Convert.ToInt32((object)h.NRZILE)) >= __date_0 && h.DATAI.AddDays((double)Convert.ToInt32((object)h.NRZILE)) < __AddDays_1 || h.DATAI <= __AddDays_1 && h.DATAI.AddDays((double)Convert.ToInt32((object)h.NRZILE)) >= __AddDays_1)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync().

public async Task<IActionResult> getOp(int day, int month, int year, int daysToShow)
{
var date = new DateTime(year, month, day);

return Ok(

await db.HT_REZ
.Where(r => (r.DATAI.AddDays(Convert.ToInt32(r.NRZILE)) >= date && r.DATAI.AddDays(Convert.ToInt32(r.NRZILE)) < date.AddDays(daysToShow))
 ||
     (r.DATAI <= date.AddDays(daysToShow) &&  r.DATAI.AddDays(Convert.ToInt32(r.NRZILE)) >= date.AddDays(daysToShow))
)
.Select(r =>
new
{
r.ID,
....
})
.ToListAsync()
);
}

I found that  implicit client evaluation has been disabled in EF Core 3,but how to make my previous query working

thanks


Viewing all articles
Browse latest Browse all 1698

Trending Articles