1

i have look into this link, same kind of conversion has to be implement for datetime

How can I configure Entity Framework to automatically trim values retrieved for specific columns mapped to char(N) fields?

Code:

 public class ConvertToLocalDateTime : DefaultExpressionVisitor
 {
  private static readonly string[] _typesToTrim = { "varchar", "datetime", String" };
  public override DbExpression Visit(DbNewInstanceExpression expression)
    {
        var arguments = expression.Arguments.Select(a =>
        {
            var propertyArg = a as DbPropertyExpression;
            if (propertyArg != null && _typesToTrim.Contains(propertyArg.Property.TypeUsage.EdmType.Name))
            {

                DateTime dt = Convert.ToDateTime(a);                    
                DbExpression outPutExp = dt.ToLocalTime();
                return outPutExp;
               // return EdmFunctions.Trim(a);

            }

            return a;
        });

        return DbExpressionBuilder.New(expression.ResultType, arguments);
    }
}

In the above code, am unable to convert "a" to Datatime.

Thanks

Community
  • 1
  • 1
Baskar
  • 11
  • 2

0 Answers0