nested linq-to-sql queries
Posted
by ile
on Stack Overflow
See other posts from Stack Overflow
or by ile
Published on 2010-05-17T12:45:10Z
Indexed on
2010/05/17
12:50 UTC
Read the original article
Hit count: 333
var result = (
from contact in db.Contacts
join user in db.Users on contact.CreatedByUserID equals user.UserID
orderby contact.ContactID descending
select new ContactListView
{
ContactID = contact.ContactID,
FirstName = contact.FirstName,
LastName = contact.LastName,
Company = (from field in contact.XmlFields.Descendants("Company")
select field.Value).SingleOrDefault().ToString()
}).Take(10);
Here I described how my database tables look like. So, contacts
table has one field that is xml
type. In that field is stored Company filename and I need to read it. I tried it using this way:
Company = (from field in contact.XmlFields.Descendants("Company")
select field.Value).SingleOrDefault().ToString()
}).Take(10);
but I get following error:
Member access 'System.String Value' of 'System.Xml.Linq.XElement' not legal on type 'System.Collections.Generic.IEnumerable`1[System.Xml.Linq.XElement].
Any solution for this?
Thanks in advance,
Ile
© Stack Overflow or respective owner