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);
}
var binding = expression.Bind();
return binding.Expression;
}
}
thank
source
share