Click here to Skip to main content
15,901,373 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: As the finely honed athletes we all are... Pin
CPallini4-Mar-18 5:40
mveCPallini4-Mar-18 5:40 
GeneralRe: As the finely honed athletes we all are... Pin
NoNotThatBob4-Mar-18 6:37
NoNotThatBob4-Mar-18 6:37 
GeneralRe: As the finely honed athletes we all are... Pin
Jörgen Andersson4-Mar-18 6:47
professionalJörgen Andersson4-Mar-18 6:47 
GeneralRe: As the finely honed athletes we all are... Pin
Eddy Vluggen4-Mar-18 7:17
professionalEddy Vluggen4-Mar-18 7:17 
GeneralRe: As the finely honed athletes we all are... Pin
Daniel Pfeffer4-Mar-18 9:30
professionalDaniel Pfeffer4-Mar-18 9:30 
QuestionRe: As the finely honed athletes we all are... Pin
Eddy Vluggen4-Mar-18 9:59
professionalEddy Vluggen4-Mar-18 9:59 
GeneralRe: As the finely honed athletes we all are... Pin
PeejayAdams4-Mar-18 23:56
PeejayAdams4-Mar-18 23:56 
GeneralThat moment when a lot of difficult work becomes a five minute job... Pin
Sander Rossel4-Mar-18 3:31
professionalSander Rossel4-Mar-18 3:31 
So I wanted to combine two select expressions in EF Core 2.0.
Something like context.MyTable.Select(e => new TModel { ... }).Select(additionalSelector).ToList();
Now that's just not possible, because the first Select converts the query to IQueryable<TModel> and the second Select has no reference to the entity (unless I put it in the model, not sure if that works, but I don't want to anyway).
So I found myself "merging" two select expressions which went awry because the "e" in additionalSelector isn't the same "e" as in the original selector [read: reference to ParameterExpression].
And Expressions are immutable... Sigh | :sigh:

So I wanted to start by converting the entire tree manually (and probably drop the idea because that isn't worth it) when I found the ExpressionVisitor[^].
All that manual work pretty much became:
C#
public class ExpressionParameterSwitcher : ExpressionVisitor
{
    private readonly ParameterExpression parameter;

    public ExpressionParameterSwitcher(ParameterExpression parameter)
    {
        this.parameter = parameter;
    }
    protected override Expression VisitParameter(ParameterExpression node)
    {
        return parameter;
    }
}
Good times Big Grin | :-D

Thought I'd post it here in case anyone ever needs it and, like me, didn't know about the ExpressionVisitor.

GeneralRe: That moment when a lot of difficult work becomes a five minute job... Pin
Marc Clifton4-Mar-18 4:01
mvaMarc Clifton4-Mar-18 4:01 
GeneralRe: That moment when a lot of difficult work becomes a five minute job... Pin
Sander Rossel4-Mar-18 6:21
professionalSander Rossel4-Mar-18 6:21 
PraiseRe: That moment when a lot of difficult work becomes a five minute job... Pin
RickZeeland4-Mar-18 4:35
mveRickZeeland4-Mar-18 4:35 
GeneralRe: That moment when a lot of difficult work becomes a five minute job... Pin
Sander Rossel4-Mar-18 6:23
professionalSander Rossel4-Mar-18 6:23 
GeneralRe: That moment when a lot of difficult work becomes a five minute job... Pin
RickZeeland4-Mar-18 6:30
mveRickZeeland4-Mar-18 6:30 
GeneralRe: That moment when a lot of difficult work becomes a five minute job... Pin
#realJSOP5-Mar-18 1:03
professional#realJSOP5-Mar-18 1:03 
GeneralRe: That moment when a lot of difficult work becomes a five minute job... Pin
Matthew Dennis4-Mar-18 6:06
sysadminMatthew Dennis4-Mar-18 6:06 
GeneralRe: That moment when a lot of difficult work becomes a five minute job... Pin
Sander Rossel4-Mar-18 6:33
professionalSander Rossel4-Mar-18 6:33 
GeneralRe: That moment when a lot of difficult work becomes a five minute job... Pin
Matthew@Home4-Mar-18 7:29
Matthew@Home4-Mar-18 7:29 
GeneralRe: That moment when a lot of difficult work becomes a five minute job... Pin
Sander Rossel5-Mar-18 6:47
professionalSander Rossel5-Mar-18 6:47 
GeneralRe: That moment when a lot of difficult work becomes a five minute job... Pin
Jörgen Andersson4-Mar-18 21:32
professionalJörgen Andersson4-Mar-18 21:32 
GeneralRe: That moment when a lot of difficult work becomes a five minute job... Pin
Slow Eddie5-Mar-18 2:35
professionalSlow Eddie5-Mar-18 2:35 
GeneralRe: That moment when a lot of difficult work becomes a five minute job... Pin
Sander Rossel5-Mar-18 6:26
professionalSander Rossel5-Mar-18 6:26 
GeneralRe: That moment when a lot of difficult work becomes a five minute job... Pin
Sundance Kid15-Mar-18 0:58
Sundance Kid15-Mar-18 0:58 
GeneralA time-zone question... Pin
Kornfeld Eliyahu Peter3-Mar-18 21:25
professionalKornfeld Eliyahu Peter3-Mar-18 21:25 
JokeRe: A time-zone question... Pin
RickZeeland4-Mar-18 1:16
mveRickZeeland4-Mar-18 1:16 
GeneralRe: A time-zone question... Pin
Kornfeld Eliyahu Peter4-Mar-18 1:32
professionalKornfeld Eliyahu Peter4-Mar-18 1:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Straw Poll

Were you affected by the geomagnetic storms this past weekend?
Communication disruptions, electrified pipes, random unexplained blue-screens in Windows - the list of effects is terrifying.
  Results   504 votes