Solved

LINQ to SQL - tables with foreign keys

Posted on 2013-05-16
3
719 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
[X]
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
  • 2
3 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 500 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

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…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

690 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