How do I reuse an Expression on a single object in another Expression

后端 未结 2 424
清歌不尽
清歌不尽 2021-01-23 06:42

I feel like I am missing something simple, but I have not found the documentation that answers my question.

I have recently been decomposing some of the linq projection

2条回答
  •  清酒与你
    2021-01-23 07:01

    You can use LINQKit to expand the expressions that you have within other expressions:

    private static Expression> CreateDepartmentDtoUnexpanded = d => new DepartmentDto
    {
        Manager = CreatePersonDto.Invoke(d.Manager),
        Employees = d.Employees.Select(employee => CreatePersonDto.Invoke(employee))
            .ToList(),
    };
    public static Expression> CreateDepartmentDto = CreateDepartmentDtoUnexpanded.Expand();
    

提交回复
热议问题