From: shapper on
On Nov 10, 2:40 am, Arne Vajhøj <a...(a)vajhoej.dk> wrote:

What about:

Dictionary<Int32, B> Bs = _Bs.Root.Elements("B").ToDictionary(b =>
(Int32)b.Element("Id"), b => new B { Id = (Int32)b.Element("Id") });

List<A> = _As.Root.Elements("A").Select(a => new A {
Id = Int32.Parse(a.Element("Id").Value),
Title = a.Element("Title").Value,
Bs = _ABs.Root.Elements("AB")
.Where(ab => ab.Element("Id").Value == a.Element
("Id").Value)
.Select(ab => Bs[Int32.Parse(ab.Element
("BId").Value)]).ToList()
}).ToList();

It compiles and is seems "cleaner" than using the loops.

From: Arne Vajhøj on
shapper wrote:
> On Nov 10, 2:40 am, Arne Vajh�j <a...(a)vajhoej.dk> wrote:
>> But why? Since the XDocument are in memory, then there
>> are not really any overhead of doing multiple LINQ's.
>
> Yes,
>
> I was trying to do it in a single Linq query:

> I am a little bit confused about your loops.
> In my code, I think you are doing it, can't I get (in my Select
> statement) the values of Bs which id is equal to ab.
>
> Don't Linq convert into loops internally?

Yes.

> So this should be possible using a single Linq Query.

Maybe.

Arne

From: Arne Vajhøj on
shapper wrote:
> On Nov 10, 2:40 am, Arne Vajh�j <a...(a)vajhoej.dk> wrote:
> What about:
>
> Dictionary<Int32, B> Bs = _Bs.Root.Elements("B").ToDictionary(b =>
> (Int32)b.Element("Id"), b => new B { Id = (Int32)b.Element("Id") });
>
> List<A> = _As.Root.Elements("A").Select(a => new A {
> Id = Int32.Parse(a.Element("Id").Value),
> Title = a.Element("Title").Value,
> Bs = _ABs.Root.Elements("AB")
> .Where(ab => ab.Element("Id").Value == a.Element
> ("Id").Value)
> .Select(ab => Bs[Int32.Parse(ab.Element
> ("BId").Value)]).ToList()
> }).ToList();
>
> It compiles and is seems "cleaner" than using the loops.

If you like it then fine.

I think it is very difficult to read and understand.

Loops are very simple constructs that are well known by
all developers. I can not see any reason to write complicated
code to avoid them.

Arne