sql to linq translated code
- by ognjenb
SQL:
SELECT
o.Id,
o.OrderNumber,
o.Date,
d.Name AS 'Distributor', d.Notes AS 'DistrNotes', -- distributer
c.Name AS 'Custoer', c.Notes AS 'CustmNotes', -- customer
t.Name AS 'Transporter', -- transporter
o.InvoiceFile,
o.Notes,
o.AwbFile,
o.TrackingFile,
o.Status,
o.DeliveryNotification,
o.ServiceType,
o.ValidityDate,
o.DeliveryTime,
o.Weight,
o.CustomerId,
o.CustomerOrderNumber,
o.CustomerDate,
o.Shipment,
o.Payment,
o.TransporterId,
o.TotalPrice,
o.Discount,
o.AlreadyPaid,
o.Delivered,
o.Received,
o.OrderEnteredBy,
CONCAT(e.Name, ' ', e.Surname) AS 'IBEKO Engineer',
o.Confirmed
FROM
`order` o LEFT JOIN person d ON o.`DistributorId` = d.`Id`
LEFT JOIN person c ON o.`CustomerId` = c.Id
LEFT JOIN Transporter t ON o.`TransporterId` = t.Id
LEFT JOIN IbekoEngineer e ON o.OrderEnteredBy = e.Id
LINQ:
testEntities6 ordersEntities = new testEntities6();
var orders_query = (from o in ordersEntities.order
join pd in ordersEntities.person on o.DistributorId equals pd.Id
join pc in ordersEntities.person on o.CustomerId equals pc.Id
join t in ordersEntities.transporter on o.TransporterId equals t.Id
select new OrdersModel
{
Id = o.Id,
OrderNumber = o.OrderNumber,
Date = o.Date,
Distributor_Name = pdk.Name,
Distributor_Notes = pdk.Notes,
Customer_Name = pc.Name,
Customer_Notes = pc.Notes,
Transporter_Name = t.Name,
InvoiceFile = o.InvoiceFile,
Notes = o.Notes,
AwbFile = o.AwbFile,
TrackingFile = o.TrackingFile,
Status = o.Status,
DeliveryNotification = o.DeliveryNotification,
ServiceType = o.ServiceType,
ValidityDate = o.ValidityDate,
DeliveryTime = o.DeliveryTime,
Weight = o.Weight,
CustomerId = o.CustomerId,
CustomerOrderNumber = o.CustomerOrderNumber,
CustomerDate = o.CustomerDate,
Shipment = o.Shipment,
Payment = o.Payment,
TransporterId = o.TransporterId,
TotalPrice = o.TotalPrice,
Discount = o.Discount,
AlreadyPaid = o.AlreadyPaid,
Delivered = o.Delivered,
Received = o.Received,
OrderEnteredBy = o.OrderEnteredBy,
Confirmed = o.Confirmed
});
I translated the above SQL code into linq. SQL code return data from database but LINQ not return data. Why?