public static SelectFromBuilder FromCombinedExpression <TCombinedModel, TNewModel>(TablesList tablesList, Expression <Func <TCombinedModel, TNewModel> > prBody) { var builder = new SelectFromBuilder(); builder.LeftJoinsExpressions = tablesList.JoinExpressions; var options = new EvaluationOptions(); foreach (var tablePlaceholder in tablesList.Tables) { builder.AddTable(tablePlaceholder); // options.ParameterToTableAlias.Add(tablePlaceholder.Name, tablePlaceholder); } var tableToPlaceholder = tablesList.Tables.ToDictionary(x => x.Name); TypedExpression exp; switch (prBody.Body) { /* For: * .Select(x => new { * M1 = x.M1, * M2_name = x.M2.Name1, * M3_calc = x.M2.Id * 2, * }) */ case NewExpression newExpression: { IEnumerable <Expression> args = newExpression.Arguments; var resultProcessor = new AnonymousTypeSelectResultProcessor <TNewModel>(); builder.SelectResultProcessor = resultProcessor; foreach (var argExpression in args) { // Member is Table (like M1 = x.M1) if (argExpression is MemberExpression memberExpression && ModelsRegistry.IsTable(memberExpression.Type)) { var tablePlaceholder = tableToPlaceholder[memberExpression.Member.Name]; var table = tablePlaceholder.Table; var tableTestRawQuery = new RawQuery(); tableTestRawQuery.AppendTable(tablePlaceholder); tableTestRawQuery.Append(" IS NULL"); builder.AddSelectPart(tableTestRawQuery, KDPgValueTypeInstances.Boolean); foreach (var column in table.Columns) { var rq = new RawQuery(); rq.AppendColumn(column, tablePlaceholder); builder.AddSelectPart(rq, column.Type); } resultProcessor.AddModelEntry(table); }