How to change all properties of a DateTime value before execution

My main problem is to change the value of the property before evaluating the expression "not datetime parsing logic", since this is just one case in another case, I need to change the other value of the property from x to y

In my application with EntityFramework 6, I have the application setup for the input format "datetime" "mm / dd / yyyy" or "dd / mm / yyyy" when the user makes a request (request or save changes), I want to change all datetime format to mm / dd / yyyy, if the setting was mm / dd / yyyy, there were no changes, but if the setting was dd / mm / yyyy, then I need to convert it to mm / dd / yyyy, I need to know where and how To redefine the value of a property and achieve the goal, I am new to ExpressionVisitors.

This could be a starting point.

internal class DateTimeInterceptor : IDbCommandTreeInterceptor
{
    public void TreeCreated(DbCommandTreeInterceptionContext interceptionContext)
    {
        if (interceptionContext.OriginalResult.DataSpace == DataSpace.SSpace)
        {
            var queryCommand = interceptionContext.Result as DbQueryCommandTree;
            if (queryCommand != null)
            {
                var newQuery = queryCommand.Query.Accept(new DateTimeQueryVisitor());
                interceptionContext.Result = new DbQueryCommandTree(queryCommand.MetadataWorkspace, queryCommand.DataSpace, newQuery);
            }
        }
    }
}

internal class DateTimeQueryVisitor : DefaultExpressionVisitor
{
    public override DbExpression Visit(DbScanExpression expression)
    {
        if (!expression.Target.ElementType.MetadataProperties.Any(mp => mp.Name.GetType() == typeof(DateTime)))
        {
            return base.Visit(expression);
        }

        // here i should do the work for changing the property value
        // Change the expression

        var binding = expression.Bind();
        return binding.Expression; //should be replaced with the modified expression
    }
}

thank

+4
source share
2 answers

, , , , : 02/02/2014? , ? , DateTime :

, , - , , , .

0

datetime, . , - datetime, .

, , - , .

, mm/dd/yyyy, , dd/mm/yyyy, 12. -.

, ​​ mm/dd/yyyy, :

        try
        {
            DateTime dt = DateTime.Parse(Console.ReadLine());
            int month = dt.Month;
            string datetime = dt.ToShortDateString();
            // Do Whatever You Want With The String
            .
            .
            .
            .

        }
        catch (Exception)
        {
            Console.WriteLine("EORROR. Incorrect DateTime Format ...");
            // Now You Must Change dd/mm/yyyy to mm/dd/yyyy
            .
            .
            .
            .
        }

. , ​​ dd/mm/yyyy. , mm/dd/yyyy.

0

All Articles