?
Solved

LINQ to SQL - tables with foreign keys

Posted on 2013-05-16
3
Medium Priority
?
726 Views
Last Modified: 2013-06-04
Hello Experts,
I am having issue with writing LINQ to SQL query:

I use Entity Framework to generate Entities and try to write LINQ to extract data...

Tables:
OrderHeader  (OrderHeaderId - primary key)
OrderPayment (OrderHeaderId - foreign Key)

When i generate entities...

In OrderPayment  - i am not seeing OrderHeaderId (get set)...since they are keyed that may be the reason i am not seeing this field.


how to join this both tables in LINQ...


Here is my LINQ:  ( it is not liking bolded line..)

 lstBatchSettleRequestInfo = (from oh in _edgePier1DataConnection.OrderHeaders
                                     join op in _edgePier1DataConnection.OrderPayments on  oh.OrderHeaderId = op.OrderHeaderId                                     join reg in _edgePier1DataConnection.DynamicFields on oh.DynamicRecordId equals reg.DynamicRecordId
                                     join trans in _edgePier1DataConnection.DynamicFields on oh.DynamicRecordId equals trans.DynamicRecordId
                                     where  op.PaymentStatusId == 1
                                            && oh.OrderTypeId != 3
                                            && (op.TransactionTypeId == 52 || op.TransactionTypeId == 53)
                                            && oh.OrderHeaderId >= 9999999
                                            && reg.DynamicFieldLayoutId == 4 && reg.DynamicFieldValue != null
                                            && trans.DynamicFieldLayoutId == 5 && trans.DynamicFieldValue != null
                                     orderby oh.OrderHeaderId, op.CreateDate ascending
                                     select new BatchSettleRequestInfo
                                            {MerchantReferenceCode = oh.OrderHeaderId,
                                            PaymentCreateDate = op.CreateDate,
                                            PurchaseTotals_GrandTotalAmount = op.Amount,
                                            StoreID = oh.ReferenceField3,
                                            ccCaptureService_run = op.TransactionTypeId == 52 ? "true" : "",
                                            ccCaptureService_authRequestID = op.TransactionTypeId == 52 ? op.AuthTrnNo : "",
                                            ccCreditService_run = op.TransactionTypeId == 53 ? "true" : "",
                                            ccCreditService_captureRequestID = op.TransactionTypeId == 53 ? op.AuthTrnNo : ""
                                            }).Distinct().ToList();




any idea?

Thanks
0
Comment
Question by:mani_sai
  • 2
3 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 2000 total points
ID: 39172034
try this change

join op in _edgePier1DataConnection.OrderPayments on  oh.OrderHeaderId equals op.OrderHeaderId   ...

AW
0
 
LVL 8

Author Closing Comment

by:mani_sai
ID: 39219622
Thanks
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 39219759
Glad to be of assistance
AW
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

807 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