[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do you create a Join statement using LINQ

Posted on 2009-04-25
2
Medium Priority
?
412 Views
Last Modified: 2013-12-17
I am trying to create a join statement using LINQ.  I tried using the example from Microsoft but get an error message.  Can someone point out where I am going wrong.  The demonstration I tried to use from MS was

http://msdn.microsoft.com/en-us/vbasic/bb688085.aspx

Maybe you can only do this in Visual Basic and not C#.  I am not sure

Here is my code that I tried to setup.


Basically, I am trying to create a join between the Patient table and the MPI table using MPI and the key field between the join.



The error messages I get are

1) A query body must end with a select clause or a group clause

2) Invalid expression term 'in'      

3) ; expected      

Here is my code
      
protected void UltraWebGridPatSrch_InitializeDataSource(object sender, UltraGridEventArgs e)
        {
            bool authenticated;
            authenticated = Convert.ToBoolean(Session["authenticated"]);
 
            if (authenticated)
            {
 
 
                RadRelayDataClassDataContext dcRadRelay = new RadRelayDataClassDataContext();
 
                // Read  Table "Providers"
 
                int RefDocPracticeTIN;
                RefDocPracticeTIN = Convert.ToInt32(Session.Contents["RefDocPracticeTIN"].ToString());
 
                var PatAttndByDocResult = from patattndbydocdata in dcRadRelay.PATIENTS_ATTENDED_BY_DOCTORs
                                          where patattndbydocdata.PracticeTIN == RefDocPracticeTIN
 
                                          select new { patattndbydocdata };
 
                int patattndbydocCount = PatAttndByDocResult.Count();    // <===== Added this line to get total count here
 
                if (patattndbydocCount == 0)                    // <===== Changed this line so that the query does not get executed again
                {
                    // No user record found
                }
                else
                {
                    foreach (var PatAttndByDocResultRecord in PatAttndByDocResult)
                    {
ERRORS Occur on the NEXT LINE BELOW------------------------
                        var PatientResult = from patientdata in dcRadRelay.PATIENTs, mpidata in dcRadRelay.MPIs
                                            where patientdata.MPI == PatAttndByDocResultRecord.patattndbydocdata.MPI &&
                                            (patientdata.FIRST_NAME == tbDocFname.Text ||
                                            patientdata.LAST_NAME == tbDocLname.Text ||
                                            patientdata.ADDRESS1 == tbDocLname.Text ||
                                            patientdata.CITY == tbDocCity.Text ||
                                            patientdata.PHONE == tbDocState.Text ||
                                            patientdata.SSN == tbDocZip.Text )

Open in new window

0
Comment
Question by:kwh3856
2 Comments
 
LVL 14

Accepted Solution

by:
PockyMaster earned 2000 total points
ID: 24233245

  var PatientResult = from patientdata in dcRadRelay.PATIENTs
                 join mpidata in dcRadRelay.MPIs on patientdata.MPI equals PatAttndByDocResultRecord.patattndbydocdata.MPI 
where
                                            (patientdata.FIRST_NAME == tbDocFname.Text ||
                                            patientdata.LAST_NAME == tbDocLname.Text ||
                                            patientdata.ADDRESS1 == tbDocLname.Text ||
                                            patientdata.CITY == tbDocCity.Text ||
                                            patientdata.PHONE == tbDocState.Text ||
                                            patientdata.SSN == tbDocZip.Text )
select patientData
                                        ;

Open in new window

0
 

Author Closing Comment

by:kwh3856
ID: 31574554
PockyMaster,
THANK YOU VERY MUCH!!!!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Screencast - Getting to Know the Pipeline
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

834 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