2

I got two tables OrderHead and Labeldata, both these two tables don't have any relationship. I want to extract data from these two table, I am using following LINQ:

var ODetail = (
    from o in oContext.OrderHeads
    join l in oContext.LIT04LABELDATA on o.CUSTORD equals l.ORDERNUMBER
    where l.ORDERNUMBER == oNumber
    select new { LIT04LABELDATA = l, OrderHead = o }
).ToList();

I want to use the data from both these tables, but I don't know how to extract data from the variable oDetail, any suggestions?

1
  • Can you specify the expected number of results from each table? Commented Nov 23, 2011 at 11:38

2 Answers 2

2

You're creating an anonymous type which has two types as its properties. Unlike in a SQL query, the hierarchy is preserved here so oDetail won't contain CUSTORD but oDetail.OrderHead will. You need to query as:

foreach(var detail in ODetail)
{
    Console.WriteLine( detail.LIT04LABELDATA.ORDERNUMBER + "   " + detail.ORDERHEAD.CUSTORD );
}
Sign up to request clarification or add additional context in comments.

Comments

0
var b=oContext.OrderHeads
.Where(p => oContext.LIT04LABELDATA.Where(q=>q.ORDERNUMBER==oNumber)
      .Select(q => q.ORDERNUMBER).Contains(p.CUSTORD))
.Select(p => new
{
    LIT04LABELDATA = oContext.LIT04LABELDATA
       .FirstOrDefault(q=>q.ORDERNUMBER==p.CUSTORD),
    OrderHead =p,
}).ToList();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.