refactoring LINQ IQueryable expression to remove duplicated portions of queries

前端 未结 3 756
滥情空心
滥情空心 2021-02-09 11:40

I have some linq queries that have redundancy I\'d like to factor out a single piece of code. These are join experssions that are IQueryable, and its important I don\'t cause t

3条回答
  •  失恋的感觉
    2021-02-09 12:20

    Another important way to factor linq expressions is to pass expressions around, for example:

    X GetSomeX(Expression> map)
    {
        return SourceOfYs.Select(map);
    }
    

    I got the idea by looking into the article of Barak's article - and even though he does a bit more on that topic, I thought I mention this piece again here. It seems to be an obvious first thing to point out directly.

提交回复
热议问题