Possible to assign LINQ join results to original outer?

L

Lars-Erik

Hi!

I've been fiddling with composing objects with partial data in two
data-stores.
I'd like to join them 1-1 and put the inner objects on a corresponding
property on the outer one.
What I can't figure out is how to do this without creating new objects of
the outer type, assigning all properties of the outer anew, and the innter to
the correct property.

IE.
(outer, inner) => new OuterType { Prop1 = outer.Prop1, ..., InnerProp =
inner }

This tends to be a bit verbose. (and does a whole new lot of instancing)

What I'd like is this, which compiles, but don't work:

(outer, inner) => { outer = outer; outer.InnerProp = inner; }

Which in my head would keep the outer object as the main object in the
resulting enumerable with the inner object neatly assigned to its InnerProp
property. :)

Is it possible?
 
L

Lars-Erik

Never mind...
I clicked post, thought about it for five more seconds, and wham:
(outer, inner) => { outer.InnerProp = inner; return outer; }

The previous code of course did not compile without the return statement,
but give a rather confusing compile exception. ;) (Arguments cannot be
inferred from the usage)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top