My main concern is changing the property value before expression evaluation "not datetime parsing logic" as it's just one case in other case i need to change other property value from x to y
In my application with EntityFramework 6 i have application setting for datetime input format "mm/dd/yyyy" or "dd/mm/yyyy", when a user make a request (querying or saving changes) i want to change all datetime format to mm/dd/yyyy, if setting was mm/dd/yyyy no changes needed, but if setting was dd/mm/yyyy then i need to convert it to mm/dd/yyyy, i need to know where and how to override the property value and achieve the goal, i'm novice in ExpressionVisitors.
This could be the 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 you