Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Linq syntex help

Posted on 2010-08-15
3
350 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

809 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