How can i have different LINQ to XML quries based on two different condition?

Posted by Subhen on Stack Overflow See other posts from Stack Overflow or by Subhen
Published on 2010-04-01T12:01:35Z Indexed on 2010/04/01 12:03 UTC
Read the original article Hit count: 225

Filed under:
|
|

Hi , We want the query result should be assigned with two results based on some condition like following:

var vAudioData = (from xAudioinfo in xResponse.Descendants(ns + "DIDL-Lite").Elements(ns + "item")

if((xAudioinfo.Element(upnp + "artist")!=null)
{
 select new RMSMedia
{
strAudioTitle = ((string)xAudioinfo.Element(dc + "title")).Trim()
};
}
else
 select new RMSMedia
{
strGen = ((string)xAudioinfo.Element(dc + "Gen")).Trim()
};

The VarAudioData should contain both if and else condition values.

I have added the if condition just to project , what is my needs, m quite sure though that we can not use if and else.

Please help if there are any other approach to accomplish this.

Thanks,

Subhen

© Stack Overflow or respective owner

Related posts about linq-to-xml

Related posts about LINQ