Rename field in a lambda

1

In SQL I do this:

select campo1 as teste from tabela

And in a lambda ? How would I do it? I have this lambda with multiple tables and the ValuePayment field repeats several times.

var qry = db.User.Join(db.Solicitation, user => user.UserID, sol => sol.UserID, (user, sol) => new { user, sol })
                    .Join(db.Payments, sol => sol.sol.SolicitationID, py => py.SolicitationID, (sol, py) => new { sol, py })
                    .Join(db.RefundKM, sol => sol.sol.sol.SolicitationID, km => km.SolicitationID, (sol, km) => new { sol, km })
                    .Join(db.Refund, sol => sol.sol.sol.sol.SolicitationID, re => re.SolicitationID, (sol, re) => new { sol, re })
                    .Select(syn => new
                    {
                        syn.sol.sol.sol.user.EmployeeID,
                        syn.sol.sol.sol.user.EmployeeStatus,
                        syn.sol.sol.sol.user.EmployeeFirstName,
                        syn.sol.sol.sol.user.Grade,
                        syn.sol.sol.sol.sol.SolicitationID,
                        syn.sol.sol.sol.sol.StatusSolicitation,
                        syn.sol.sol.sol.sol.DateFinancing,
                        syn.sol.sol.sol.sol.Manufacturer,
                        syn.sol.sol.sol.sol.Chassi,
                        syn.sol.sol.sol.sol.Model,
                        syn.sol.sol.sol.sol.ValueProperty,
                        syn.sol.sol.sol.sol.ValueGranted,
                        syn.sol.sol.py.PaymentStatus,
                        syn.sol.sol.py.ValuePayment,
                        syn.sol.sol.py.ValueInterest,
                        syn.sol.km.ValuePayment,
                        syn.re.ValuePayment

                    });
    
asked by anonymous 17.09.2018 / 19:23

2 answers

4

Just match the property with a name of your choice, eg:

empId = syn.sol.sol.sol.user.EmployeeID

In your code something like this:

var qry = db.User.Join(db.Solicitation, user => user.UserID, sol => sol.UserID, (user, sol) => new { user, sol })
    .Join(db.Payments, sol => sol.sol.SolicitationID, py => py.SolicitationID, (sol, py) => new { sol, py })
    .Join(db.RefundKM, sol => sol.sol.sol.SolicitationID, km => km.SolicitationID, (sol, km) => new { sol, km })
    .Join(db.Refund, sol => sol.sol.sol.sol.SolicitationID, re => re.SolicitationID, (sol, re) => new { sol, re })
    .Select(syn => new
    {
        syn.sol.sol.sol.user.EmployeeID,
        syn.sol.sol.sol.user.EmployeeStatus,
        syn.sol.sol.sol.user.EmployeeFirstName,
        syn.sol.sol.sol.user.Grade,
        syn.sol.sol.sol.sol.SolicitationID,
        syn.sol.sol.sol.sol.StatusSolicitation,
        syn.sol.sol.sol.sol.DateFinancing,
        syn.sol.sol.sol.sol.Manufacturer,
        syn.sol.sol.sol.sol.Chassi,
        syn.sol.sol.sol.sol.Model,
        syn.sol.sol.sol.sol.ValueProperty,
        syn.sol.sol.sol.sol.ValueGranted,
        syn.sol.sol.py.PaymentStatus,
        p1 = syn.sol.sol.py.ValuePayment,
        syn.sol.sol.py.ValueInterest,
        p2 = syn.sol.km.ValuePayment,
        p3 = syn.re.ValuePayment
    });

In this example as it has 3 like, I renamed it to p1 , p2 and p3 , but the name may be of your preference.

    
17.09.2018 / 19:30
4

syn.sol.sol.sol.sol. is certainly one of the biggest absurdities I've ever seen in code and something tells me not to stop there, but I think this is what you want:

var qry = db.User.Join(db.Solicitation, user => user.UserID, sol => sol.UserID, (user, sol) => new { user, sol })
                .Join(db.Payments, sol => sol.sol.SolicitationID, py => py.SolicitationID, (sol, py) => new { sol, py })
                .Join(db.RefundKM, sol => sol.sol.sol.SolicitationID, km => km.SolicitationID, (sol, km) => new { sol, km })
                .Join(db.Refund, sol => sol.sol.sol.sol.SolicitationID, re => re.SolicitationID, (sol, re) => new { sol, re })
                .Select(syn => new {
                    EmployeeID = syn.sol.sol.sol.user.EmployeeID,
                    EmployeeStatus = syn.sol.sol.sol.user.EmployeeStatus,
                    EmployeeFirstName = syn.sol.sol.sol.user.EmployeeFirstName,
                    Grade = syn.sol.sol.sol.user.Grade,
                    SolicitationID = syn.sol.sol.sol.sol.SolicitationID,
                    StatusSolicitation = syn.sol.sol.sol.sol.StatusSolicitation,
                    DateFinancing = syn.sol.sol.sol.sol.DateFinancing,
                    Manufacturer = syn.sol.sol.sol.sol.Manufacturer,
                    Chassi = syn.sol.sol.sol.sol.Chassi,
                    Model = syn.sol.sol.sol.sol.Model,
                    ValueProperty = syn.sol.sol.sol.sol.ValueProperty,
                    ValueGranted = syn.sol.sol.sol.sol.ValueGranted,
                    PaymentStatus = syn.sol.sol.py.PaymentStatus,
                    ValuePayment = syn.sol.sol.py.ValuePayment,
                    ValueInterest = syn.sol.sol.py.ValueInterest,
                    ValuePayment = syn.sol.km.ValuePayment,
                    ValuePaymentRe = syn.re.ValuePayment
                });
    
17.09.2018 / 19:29