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 Query
- Linq - How Do I select a new object to contain a list of other objects?
- Linq select object from list depending on objects attribute
- How to use Linq to select and group complex child object from a parents list
- Using LINQ I have a list of lists, how do I select all objects that exist in every list?
- Building a new list of Object with combination of other lists of Objects
- Select List of Object Which Contain Another List by LINQ
- How to bind and save an object containing a list of objects to database context in ASP.NET MVC with EF code first?
- How can I use LINQ to select a property and also other items of a list at the same level?
- LINQ check list of objects contain a value AND not some other values
- How to use LINQ to get an object from List of objects matching option from List of options
- How to map to another object list with help of linq lambda select
- how do i pivot list of object and create new list in linq c#?
- Using linQ to group list of object into new lists of objects
- Create new list of objects for each of the item in another object list using Linq
- How to select new object set property = other property value
- List of objects where the object contains an array - how to use LINQ to search through all objects for a value in that array
- how can I Select One row where max StartDate in list objects using linq
- Return a specific object in a LINQ select query from two different objects in a list
- How to use LINQ to select object with minimum or maximum property value
- Linq select objects in list where exists IN (A,B,C)
- Using Linq to group a list of objects into a new grouped list of list of objects
- LINQ: Select where object does not contain items from list
- How to select values within a provided index range from a List using LINQ
- Return list using select new in LINQ
- Linq select to new object
- 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 - How to select items from a list that contains only items of another list?
- Linq to objects - select first object
- Linq Select New List Property Null Check
More Query from same tag
- Entity framework Include command - Left or inner join?
- Grouping in Elastic Search
- getting the elements of a Collections.Generic through refllection
- Check if column exists before execute select clause
- C# LINQ to rank time series values on a daily basis => partition by date, then rank by value (largest to smallest)
- Create new list of objects for each of the item in another object list using Linq
- Histrogram with Linq
- Linq OrderBy int property does not work
- Filter List By items in Array (LINQ)
- Performance diagnostics improves performance
- DataContext Refresh and PropertyChanging & PropertyChanged Events
- Select descendent nodes and elements from an XML using LINQ
- Show null results through the LEFT JOIN with Linq
- Select from list where not appear in second list
- Is there an implementation of IQueryable over DbDataReader?
- Changing the value of a ConstantExpression in a pre-existing BinaryExpression
- Find items within a list which exist in another list
- Need a LINQ code example to link two tables that have no foreign key
- How to return LINQ object from method?
- Linq Query in a (Pre Delete Operation) Plugin
- what is output type of method when returns result of linq query?
- get data from DataTable using LINQ
- Print array with LINQ
- how read 2 table data having one to many relation form SQL in Entity Framework
- How can I recursively iterate a date's digits and sum?
- Increasing Linq to XML Parsing performance
- LINQ to SQL - Best way for reading data from one to many mapped tables
- Entity Framework 3.5 - How to load children
- calculating the occurrence of two column values in DataTable using linq
- Hierarchy class Linq search