tags:

views:

82

answers:

1

Hi I have a number of related issues but I will break the questions down into seperate posts.

My XML is <Person>.....<Skills><Skill>Resus<Skill></Skills></Person>

My code is :

var products1 = from prd in xDoc.Descendants("Person") 

select new BusinessEntityLayer.Personnel
{
  PayrollNo = (String)prd.Element("PayrollNumber"),
  FirstName = (String)prd.Element("Name"),
  LastName = (String)prd.Element("Surname"),
  StreetAddress = (String)prd.Element("StreetAddress"),
  Suburb = (String)prd.Element("Suburb"),
  HomePhone = (String)prd.Element("HomePhone"),
  MobilePhone = (String)prd.Element("MobilePhone"),
  PagerNumber = (String)prd.Element("PagerNumber"),
  Email = (String)prd.Element("Email"),
  RecordType = (String)prd.Element("RecordType"),
  Skills = (List<String>)prd.Element("Skills")

My Personnel class is strongly typed. It all works perfectly apart from the Skills collection. Skills is List<Skill> but my code won't compile with an error - XLInq.Element to Generic.List...nor can I use String[] (refactoring my business class) as I get the same result.

What strategies do people use here?

+1  A: 

I think you should be able to do something like this:

Skills = prd.Descendants("Skill").Select(e => new Skill(e.Value)).ToList(),
Torbjörn Hansson
Thanks - that has got me further down the track!
mttumbledown
My integration issue now is that, upstream, I need to supply my XML from a dataset (out of my hands I am afraid!), How do I add a Generic Collection to a Dataset column>? dc = new DataColumn("Skills", System.Type.GetType?); dtData.Columns.Add(dc);I am able to derive my XML from ds.GetXML() so am hoping it gets deserialised correctly.If I add it as an object,I get serialisation issues.
mttumbledown