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 / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

Linq to xml and collections

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Robert Bravery - 10 Mar 2008 10:46 GMT
Hi all,

I have a contact class that has as one of its properties a segment list
collection
public List<Segment> SegmentCollection { get; set; }

In the Segment class there is a segmentname property
public class Segment
{
 public string SegmentName { get; set; }
}

In my zml I have the following:
<Contact>
 <Id>1</Id>
 <FirstName>Darrel</FirstName>
 <LastName>Schreyer</LastName>
 <UserName>Schreyer</UserName>
 <Email>darrel@winontheweb.co.za</Email>
 <Title>Mr</Title>
 <CompanyName>Win on the Web</CompanyName>
 <Position>Developer</Position>
 <Branch>Johannesburg</Branch>
 <Segments>
  <Segment>
   <SegmentName>IT</SegmentName>
  </Segment>
  <Segment>
   <SegmentName>HR</SegmentName>
  </Segment>
 </Segments>

I can get all the other elements but cannot get the segment element into my
segment collection of my contact class
Can some one show me how using linq

Thanks
Robert
Simon Hart [MVP] - 12 Mar 2008 23:19 GMT
You just need to change your code slightly, you don't need to use LINQ.

IE:

public class Contact
{
     public Segments Segments
    {
            get;
            set;
    }

       
}

public class Segments
{
   public List<Segment> Segment
   {
        get;
        set;
   }  

   public string SegmentName
   {
       get;
       set;
   }
}

You could nest the Segments class within the Contact class but in this case
with have to have different names, currently they would have to exisit in
diff namespaces or else you'd get a name conflict problem.

Serializing the above should generate the desired result.
Signature

Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com

> Hi all,
>
[quoted text clipped - 34 lines]
> Thanks
> Robert

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.