Efcore: Implement DateDiff translation

Created on 2 Dec 2017  路  3Comments  路  Source: dotnet/efcore

I'd like to order rows by an integer + number of days passed since today.

However this:

var now = DateTime.UtcNow;

db.Items.OrderBy(x => x.SomeInteger + (x.Date - now).Days);

Gives the following warning:

The LINQ expression 'orderby' could not be translated and will be evaluated locally.

In .NET framework it was possible to use this: DbFunctions.DiffDays

It seems that there isn't any equivalent in ASP.NET Core.

closed-fixed type-enhancement

Most helpful comment

Hello @isonil,
There is a PR for this. (https://github.com/aspnet/EntityFrameworkCore/pull/10264)

All 3 comments

Hello @isonil,
There is a PR for this. (https://github.com/aspnet/EntityFrameworkCore/pull/10264)

Until this is merged, @smitpatel demonstrates how to use this here: https://github.com/aspnet/EntityFrameworkCore/issues/10241#issuecomment-342989770

it's an option until we get this in EF.Functions 馃槉

@ralmsdeveloper Great, thank you. The workaround works.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

divega picture divega  路  146Comments

matteocontrini picture matteocontrini  路  88Comments

vijayantkatyal picture vijayantkatyal  路  321Comments

dgxhubbard picture dgxhubbard  路  97Comments

0xdeafcafe picture 0xdeafcafe  路  467Comments