tags:

views:

53

answers:

1

This one seems like it should be pretty straightforward, but I couldn't quite figure it out or find anything on it. My query looks something like this:

from o in objects
          select new
          {
            o.ID,
            o.member.Number,
            o.member.Date,
            o.member.total,
            o.SequenceNumber,
            o.InputDate,
            o.Amount,
            o.Discount,
            Balance = o.Balance(),
            o.otherMember.CreatedBy,
          }

Notice there are quite a few times where i access o.member. In real life this is like 20 times (I'm aggregating a dataset for a grid). What I would like to do is be able to reference it like this :

select new
          {
            o.ID,
            m.Number,
            m.Date,
            m.total,
            o.SequenceNumber,
            o.InputDate,
            o.Amount,
            o.Discount,
            Balance = o.Balance(),
            o.otherMember.CreatedBy,
          }

But I'm not sure the right syntax to use. Is it possible to alias it at the top, or with a join somehow?

+9  A: 

You can do:

from o in objects
let m = o.member
select new { /* as per question */ };
Jon Skeet
whaaat... thats awesome
Allen
+1 to Allen for making me laugh. :D
Nathan Taylor