score:17
Accepted answer
You should be going through the Product
descendants, not items. That way you are reading off of the Product
elements. Then it is easier to get the associated items.
var doc = XDocument.Load("../Content/index.xml");
var products = doc.Elements("product")
.Select(p =>
new Product
{
Name = (string)p.Attribute("name"),
ProductItems = p.Elements("item")
.Select(i =>
new ProductItem
{
//set properties for PI
Hwid = (string)i.Attribute("hwid"),
Href = (string)i.Element("href"),
Localization = (string)i.Element("localization"),
// etc.
})
.ToList()
})
.ToList();
Source: stackoverflow.com
Related Articles
- Linq - How Do I select a new object to contain a list of other objects?
- Linq select object from list depending on objects attribute
- Select List of Object Which Contain Another List by LINQ
- LINQ check list of objects contain a value AND not some other values
- Return a specific object in a LINQ select query from two different objects in a list
- Linq select objects in list where exists IN (A,B,C)
- LINQ: Select where object does not contain items from list
- LINQ select one field from list of DTO objects to array
- Linq to Select Parent Objects Where Child Objects Have a Matching Child Object
- Linq to objects - select first object
- Linq select match list from other list performance
- Linq query a List of objects containing a list of object
- C# LINQ Select objects with the same value of one property join values of other
- Select property of an object that is in a list of objects which is also in another list of objects
- Select items from a List where the children contain the items from another List using LINQ
- C# linq Select objects in list looking inside another list of objects
- Searching a List of objects in an object list using linq in VB.net
- How to use Linq to select and group complex child object from a parents list
- Using LINQ to get the difference between two list of objects based only on a single object property
- LINQ query using list of objects property of an object
- Using LINQ I have a list of lists, how do I select all objects that exist in every list?
- Linq to select list of items from custom nested list of objects
- Left join not bringing all results when you also select a list of other objects in EFCore 3.1.11
- C# Linq select object in List where int in object child List<int> occurs n times
- C# Using LINQ to filter each Object with Max Value in List of Objects
- Linq to Select Parent Objects Where Child Objects Dont contain value
- C# LINQ Order List by Object property, Select X Amount
- LINQ sample: select typed objects from a list
- C# Linq IQueryable select flattened nested object list
- LINQ - EF Core - Return object that contains two objects (referenced by property) in nested list
- Convert string join utility function into LINQ equivalent
- Associated indexes of two list
- Simple query on linq
- Filter a certain value in List according to Where using LINQ
- CSV to object model mapping
- Linq - Creating Expression<T1> from Expression<T2>
- Using split with \r\n\r\n
- Get a count list of a nested list using LINQ
- Linq Data Source WhereParameters with "\" in value
- Sort items arbitrarily using external priority list
- Linq Select * from Table ExecuteQuery
- Converting one XML document into another XML document
- How to map Integer to String with AutoMapper 3 and Entity Framework
- linq (right) join does not return correct number of objects
- Flattening a loop with lookups into a single linq expression
- Query for fetching data from joining table
- LINQ group by sum not working as expected
- ASP.NET / XML : Using a linq query to get the values of one node
- Comparing Datetime? inside Linq Expression
- IQueryable does not contain a definition for 'Select'