score:3
Accepted answer
You can use the let
clause to declare intermediate variables:
XDocument reportDoc = XDocument.Load(@"Report.xml");
var query = from item in reportDoc.Element("Root").Descendants()
let x = Convert.ToInt32(ticket.Element("X").Value)
let y = Convert.ToInt32(ticket.Element("Y").Value)
select new Item()
{
X = x,
Y = y
Z = x * y
};
Source: stackoverflow.com
Related Articles
- How to set a DTO's property value directly in LINQ select statement
- How to use LINQ to select object with minimum or maximum property value
- C# LINQ Select objects with the same value of one property join values of other
- update a property value during linq to sql select (involves join)
- Complex Linq query to select list items with another list property containing a value
- select and update based on a child objects property minimum value using Linq
- How to dynamically get a property value in which is in another property with Linq where statement
- Linq to entities use `Func` to create property in a select statement that produces an anonymous object
- Linq extension. Change property value in source list
- Linq select where entity property value matches value of property of any item in another List
- Using a Linq query to select objects where any value of a property matches values from a list
- LINQ Delegate Lambda Select Statement Bind Child Property
- Always select true/higher value in LINQ statement group by (Multiple columns)
- C# LINQ accessing another property within a LINQ SELECT statement (method)
- Assign List property on Select LINQ statement
- C# LINQ select hierarchy from list where root has a certain property value
- LINQ - Select Statement - The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type
- Linq code to select one item
- How to use Lambda in LINQ select statement
- Select most frequent value using LINQ
- Linq : select value in a datatable column
- Using a partial class property inside LINQ statement
- C# LINQ select from where value is not contained in array / list
- FirstOrDefault behavior directly in LINQ statement
- Filter linq list on property value
- LINQ How to select more than 1 property in a lambda expression?
- linq remove item from object array where property equals value
- Select one parent property and all children using linq
- LINQ - Returning value of a property of an object that is not null
- LINQ select property by name
- What's the difference between FindAll and Select?
- How to a List using LINQ Query?
- Using LINQ to SQL where database tables can have extra columns
- Datatable updating without using datarow loop
- C# Linq equivalent for SQL script not responding
- LINQ vs foreach vs for performance test results
- Comparing object with Nothing in vb.net
- Compare the item from one list object with another item from another list object
- Why is LINQ's default ID(Primary Key) ReadOnly=False?
- What's the underscore.js equivalent to LINQ's SelectMany operator?
- LINQ: Sort by (Treat letters as numbers)
- Read XML element from free geo location service
- TSQL Loop through two queries to insert into another table
- Different result in Linq with GroupBy and Count
- linq: how to set condition that select all the records generated within the last 20 minutes?
- Distinct Query?
- Initialie a Query
- How to query child tables values
- Writing an extension method to help with querying many-to-many relationships
- Merge multiple Lists into one List with LINQ