pkolodziej (2) [Avatar] Offline
#1
Hi

According to the listing 11.13 (Presenting Reviews from Sql DB and XML)

select new {
Title = book.Title,
Reviews =
from reviewElement in bookElement.Descendants(ns + "Review")
orderby (int)reviewElement.Element(ns + "Rating") descending
select new Review {
Rating = (int)reviewElement.Element(ns + "Rating"),
Comments = (string)reviewElement.Element(ns + "Content")
}
};

I was expecting author will "Split" the reviews from book and bookElement. Reviews come only from reviewElements for now. Is there an easy and elegant way to do it?

Best Regards
Piotr Kołodziej
fabrice.marguerie (224) [Avatar] Offline
#2
Re: Liting 11.13 - Joining results from XML and DB
Hi Piotr,

I don't understand what you mean by "split" the reviews. Could you be more explicit, please?
Do you mean "merge" reviews from book and bookElement?

Fabrice
pkolodziej (2) [Avatar] Offline
#3
Re: Liting 11.13 - Joining results from XML and DB
Yes. That is exactly what I ment. My mistake.
fabrice.marguerie (224) [Avatar] Offline
#4
Re: Liting 11.13 - Joining results from XML and DB
If you want to merge items from two sequences, you can use of one the Set query operators. Here, the Union query operator is probably what you're after.

What do you think of the following?:

[pre]select new {
Title = book.Title,
Reviews =
(from reviewElement in bookElement.Descendants(ns + "Review")
orderby (int)reviewElement.Element(ns + "Rating") descending
select new Review {
Rating = (int)reviewElement.Element(ns + "Rating"),
Comments = (string)reviewElement.Element(ns + "Content")
}).Union(book.Reviews)
};[/pre]