I am working with LINQ and MS SQL using c#. I am facing a problem in fetching records. I have 2 tables as,
Sales
Transactions
Sales primary key is being referred by Transactions table.Data is like,

What I am trying to do is to fetch all the records with amount != 0. In this example, the result should include only Sales2 and Sales3, but not Sales1. Since Sales1 is closed.
I have written a query like,
List<Sales> lstSales = (from ccs in context.Sales
join transactions in context.Transactions
on ccs.SALESID equals transactions.SALESID
where transactions .AMOUNT !=0
select ccs).ToList();
It returns me all the 3 Sales records, because for 1 row against Sales1, amount !=0.
Please guide me to achieve the desired results.
Thanks in advance,
Vijay
Though your query filter out the closed transactions, still you have > 0 transactions in the result so you still get the Sales1 Id.
Try this instead (it should work, though I haven’t tested this);
Another approach is (assuming you have an association between Sales and Transaction in the context);