Solved

Linq syntex help

Posted on 2010-08-15
3
346 Views
Last Modified: 2013-11-11
       Dim Query = From Supp In db.Suppliers _
                           Group Join RO In db.ReceiveOrders _
                On RO.SupplierNo Equals Supp.SupplierID _
                Into RightTableResults = Group _
        From Contact In RightTableResults.DefaultIfEmpty _
             Select ContactName = If(Supp Is Nothing, Nothing, _
        If(Supp Is Nothing, New Supplier, Supp).ContactName), Supp.Name

This query works great, now I need to add this line to join in one more table:

 Join ROE In db.ReceiveEntries On RO.ReceiveID Equals ROE.ReceiveNo

I can't figure out how to do it, can some one help me with that?

(the SQL syntax is very simple:
SELECT     Supplier.Name, ReceiveEntry.Cost, ReceiveEntry.Qty, ReceiveOrder.ReceiveOrderDate
FROM         ReceiveEntry INNER JOIN
                      ReceiveOrder ON ReceiveEntry.ReceiveNo = ReceiveOrder.ReceiveID RIGHT OUTER JOIN
                      Supplier ON ReceiveOrder.SupplierNo = Supplier.SupplierID)
 
0
Comment
Question by:Mr_Ezi
3 Comments
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33441655
try this link there is an sql to linq Converter...
http://www.sqltolinq.com/
0
 
LVL 14

Expert Comment

by:PockyMaster
ID: 33443981
If there's a relationship in your database between ReceiveEntry and ReceiveOrder you should be able to simply add the receive entries to your select.

e.g. (don't know the VB syntax... but in C# it would be something like)
select new
{
    Supp.ContactName,  // replace this with the if statements you had
    Supp.Name,
    Entries = RO.ReceiveEntries
}
0
 
LVL 12

Accepted Solution

by:
kumar754 earned 500 total points
ID: 33534615
based on your code, try the attached linq query,
I guess you can easily convert it into VB.NET


 var query = from supp in db.Suppliers

	     join recOrder in db.ReceiveOrder

		on supp.SupplierID equals ReceiveOrder.SupplierNo into recOrderGroup

	     join recEntry in db.ReceiveEntry

		on recOrder.ReceiveID equals recEntry.ReceiveNo into recEntryGroup

	     from recOrder in recOrderGroup.DefaultIfEmpty()

	     from recEntry in recEntryGroup.DefaultIfEmpty()

	     select new {

		supp.Name, 

		recEntry.Cost, 

		recEntry.Qty, 

		recOrder.ReceiveOrderDate

	     };

Open in new window

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now