public override DbExpression Visit(DbNewInstanceExpression expression) { Check.NotNull(expression, "expression"); DbExpression result = expression; var newType = VisitTypeUsage(expression.ResultType); var newArguments = VisitExpressionList(expression.Arguments); var unchanged = (ReferenceEquals(expression.ResultType, newType) && ReferenceEquals(expression.Arguments, newArguments)); if (expression.HasRelatedEntityReferences) { var newRefs = VisitList(expression.RelatedEntityReferences, VisitRelatedEntityRef); if (!unchanged || !ReferenceEquals(expression.RelatedEntityReferences, newRefs)) { result = CqtBuilder.CreateNewEntityWithRelationshipsExpression((EntityType)newType.EdmType, newArguments, newRefs); } } else { if (!unchanged) { result = CqtBuilder.New(newType, newArguments.ToArray()); } } NotifyIfChanged(expression, result); return(result); }