views:

43

answers:

1

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

+3  A: 
from xAudioinfo in xResponse.Descendants(ns + "DIDL-Lite").Elements(ns + "item")
select new RSMedia
{
   strAudioTitle = (xAudioinfo.Element(upnp + "artist") != null) 
      ? ((string)xAudioinfo.Element(dc + "title")).Trim()
      : null,
   strGen = (xAudioinfo.Element(upnp + "artist") == null) 
      ? ((string)xAudioinfo.Element(dc + "Gen")).Trim()
      : null
}

You could also utilize a union, which may look a little nicer... this is just as effective though.

Brian