tags:

views:

85

answers:

1
let order= _relationContext.Orders 
             .Where(x => x.OrderNumber == orderNo)
             .Select(x => new { x.OrderNo, x.OrderDate }).Single()

I want to try and do something like this

let order = _relationContext.Orders join _relationContext.Products 
                     .Where(x => x.OrderNumber == orderNo && x.ProductId == Products.ProductID)
                     .Select(x => new { x.OrderNo, x.OrderDate }).Single()

Is this even possible?

UPDATE 1: My current code

    var q = from c in sXDocument.Descendants("prop")
        let handle = c.Element("handle")
        let resultref = handle != null ? handle.Element("dsref") : null
        let orderno = (string)c.Element("orderno")
        let orderdetail = _relationContext.Order 
                        .Where(x => x.orderno == orderno)
                        .Select(x => new { x.ProductID, x.OrderDate }).Single()

        select new Order()
        {
            OrderNo = orderno,
            Handle = resultref != null ? (string)resultref.Attribute("handle") : null,
            Title = //Need ProductName,

            ProductID = orderdetail.ProductID.ToString(),
        };

return q.ToList();

I figured that if I could use a join in let keyword so I could get the product name

+4  A: 

You can only use "let" as part of a query expression. If you want to define a separate variable, just declare it in the normal way. If you could give us more idea of what you're trying to do, that would really help.

EDIT: You can use "join" within a "let" clause, but only if it's a full query expression inside:

from foo in foos
let bar = (from x in baz join y in qux on x.Id equals y.Id select ...)
select ...

Are you sure you shouldn't be using a join instead of a let to start with?

Jon Skeet
Jon: I posted my current code in Update 1
uno
Jon: reason I went with my thought process was that let orderno = (string)c.Element("orderno") gets me diff orderNo from my xml file - so this way i figured I could do a join in a let.
uno
@uno: How can it be giving you a different order number from the one in the XML?
Jon Skeet
Jon: I meant to say - the xml returns say 5 order details - this means 5 order numbers. hence I choose to code the way I have in my sample. And if the products ordered in an order were different, I was looking for a solution of trying to use a join in a let statementSomething tells me that I am on the wrong path.
uno
@uno: It doesn't feel particularly usual, to be honest. Unfortunately I don't quite have time to get my head round your situation at the moment :(
Jon Skeet
Jon: np. Maybe I can email you at the address in your profile? This way in future if you have a few moment to spare on my trivial matter you can enlighten me. This is my test project - trying to learn something new
uno
@uno: Sure - but I don't guarantee to find any time in the near future. I may, but it depends on many things :)
Jon Skeet