flindeberg is correct when it says that System.Linq.Dynamic parses an expression that you give as C #, not SQL.
However, the Entity Framework defines the "DbFunctions" class, which allows you to call sql functions as part of your Linq queries.
DbFunctions.DiffDays is the method you are looking for. However, you also do not need to use System.Linq.Dynamic.
Your code will look something like this, I think:
var _list = new vsk_error_log(); using ( var entities = new vskdbEntities() ) { _list = entities.vsk_error_log .Where( entry => DbFunctions.DiffDays( entry.added_date, DateTime.UtcNow ) == 0 ) .ToList(); } return _list;
If you want to use this function with System.Linq.Dynamic, it will look something like this:
var _list = new vsk_error_log(); using ( var entities = new vskdbEntities() ) { _list = entities.vsk_error_log .Where( "DbFunctions.DiffDays( added_date, DateTime.UtcNow ) == 0" ) .ToList(); } return _list;
BUT! System.Linq.Dynamic does not recognize the DbFunctions class, and therefore it will not work out of the box. However, we can βfixβ this function using a little reflection, although it can be a little ugly:
var type = typeof( DynamicQueryable ).Assembly.GetType( "System.Linq.Dynamic.ExpressionParser" ); FieldInfo field = type.GetField( "predefinedTypes", BindingFlags.Static | BindingFlags.NonPublic ); Type[] predefinedTypes = (Type[])field.GetValue( null ); Array.Resize( ref predefinedTypes, predefinedTypes.Length + 1 ); predefinedTypes[ predefinedTypes.Length - 1 ] = typeof( DbFunctions ); field.SetValue( null, predefinedTypes );
By running this code, System.Linq.Dynamic now recognizes DbFunctions as a type that can be used in C # expressions.