Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

Linq and sql

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ilyas - 13 Mar 2008 19:24 GMT
Hi all

I have the following xml file :

<?xml version="1.0" encoding="utf-8" ?>
<root>
    <persons>
        <person>
            <firstname>Mark</firstname>
            <surname>Jones</surname>
            <age>33</age>
        </person>
        <person>
            <firstname>Adbul</firstname>
            <surname>Khan</surname>
            <age>30</age>
        </person>
        <person>
            <firstname>Bob</firstname>
            <surname>Smith</surname>
            <age>31</age>
        </person>
    </persons>
</root>

I have the following expression

XElement myXml = XElement.Load("Sample.xml");

var allPersonsInOrderOfAge = from person in
myXml.Descendants("person") orderby person.Element("age") select
person;

However when I run this - I get an error saying "At least one object
must implement IComparable"

Can anyone shed any light on this? Is my expression wrong... How can I
correct this problem?

Many thanks
David R. Longnecker - 13 Mar 2008 21:25 GMT
> var allPersonsInOrderOfAge = from person in
> myXml.Descendants("person") orderby person.Element("age") select
> person;

You need to cast your person.Element("age") to a type so it knows how to
compare the elements:

var allPersonsInOrderOfAge =
               from person in myXml.Descendants("person")
               orderby (int)person.Element("age")
               select person;

Hope this helps.

-dl

--
David R. Longnecker
http://blog.tiredstudent.com

> Hi all
>
[quoted text clipped - 35 lines]
>
> Many thanks

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.