0

I have two variables Income and Expense, I want to union this two variables and put the result into a sumSalary variable, but I always get an error (the error in sumSalary at Income). Please help me solve this problem.

public void PayrollReport()
{
    var income = employeeList.SelectMany(a => a.IncomesModel,(a,b) => new 
            {
                a.Salary,
                a.HolidayAllowance,
                EmployeeNik = a.NIK,
                EmployeeName = a.FirstName,

                b.Amount,
                b.ModelType,
                b.PeriodTime
            });

    var expense = employeeList.SelectMany(a => a.ExpensesModel, (a, b) => new
            {
                EmployeeNik = a.NIK,
                EmployeeName = a.FirstName,

                b.Amount,
                b.ModelType
            });

    var sumSalary = income.Union(expense);
}
3
  • Possible duplicate of Union in entity framework Commented Oct 24, 2019 at 2:15
  • 1
    How are you expecting the Union to work given the first query returns different columns (e.g. Salary) than the second? Commented Oct 24, 2019 at 2:21
  • 1
    you need to have the same exact properties on both anonymous types to make it work. Commented Oct 24, 2019 at 4:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.