I have 3 tables without foreign keys (it's a legacy db, so I can't change that). The model will be something like this (sql code):
Select
PROD.ProductoId,
PROD.Descripcion,
STK.StockActual,
DEPO.DepositoId,
DEPO.Descripcion
From
Productos PROD,
Stock STOK,
Depositos DEPO
where
PROD.ProductoId = STOK.ProductoId
and DEPO.DepositoId = STOK.DepositoId
How can I do to get the same results with Linq on C#?
Try this:
var result = from prod in _context.Productos
join stok in _context.Stocks on prod.ProductoId equals stok.ProductoId
join depo in _context.Depositos on stok.DepositoId equals depo.DepositoId
select new
{
ProductoId = prod.ProductoId,
ProductoDescripcion = prod.Descripcion,
StockActual = stok.StockActual,
DepositoId = depo.DepositoId,
DepositoDescripcion = depo.Descripcion
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With