score:3
1. you have mixed lambda expression with linq syntax. started with linq and end with lambda expression. try this
var q = xmldoc.descendants("site").where(tech => tech.attribute("technical").value == "true")
.select(n => new { sitename = n.element("name").value});
or you should be using the whole query in linq
var q = from c in xmldoc.descendants("site") where c.attribute("technical").value == "true"
select new { sitename = c.element("name").value};
2. just use todictionary in the end of query
var q = xmldoc.descendants("site").where(tech => tech.attribute("technical").value == "true")
.select(n => new { sitename = n.element("name").value,key= n.element("id").value }).todictionary(n=>n.key,l=>l.sitename);
n=>n.key will the key for dictionary and l=>l.sitename will be value.
3. there are two ways of create such queries one is using linq other is using methods that uses lambda expressions as parameter. both are easy, linq is somehow like sql query while methods use lambda are more like a short hand for manipulating data by description methods. i personally like method oriented way with lambda as its more sequentially readable.
Source: stackoverflow.com
Related Query
- The type of the expression in the select clause is incorrect. Type inference failed in the call to 'Select'
- The type of the expression in the select clause is incorrect. Type inference failed in the call to 'Select'
- The Type of one of the Expression in the join clause is incorrect.Type inference failed in the call to join
- The type of one of the expressions in the join clause is incorrect in Entity Framework
- LINQ - 'The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'GroupJoin'.'
- The type of one of the expressions in the join clause is incorrect when the types are the same
- C# Linq to Entities: The type of one of the expressions in the join clause is incorrect. Type inference failed
- The type of one of the expressions int he join clause is incorrect. Type inference failed in the call to 'join'
- Error "The LINQ expression node type 'Invoke' is not supported in LINQ to Entities" in where clause inside the method
- Type of one of the expressions in the join clause is incorrect
- Dynamicaly changing the type of a parameter in an Expression without knowing the target type at code time
- Why does this linq query fail when I change the select clause to select new Model
- Lambda expression C# failed to convert to the object type and fail with ref
- What causes error "The type of the expression in the let clause is incorrect."
- C# Linq to SQL: The type of one of the expressions in the join clause is incorrect. Type inference failed
- The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'
- The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'GroupJoin'
- I am having trouble with the code below. It is saying 'results' is an expression type '?'. which is not a collection type
- The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities
- Mutating the expression tree of a predicate to target another type
- How to create LINQ Expression Tree to select an anonymous type
- Could not find an implementation of the query pattern for source type 'System.Data.Entity.DbSet'
- lambda expression join multiple tables with select and where clause
- The LINQ expression node type 'Invoke' is not supported in LINQ to Entities in entity framework
- Type inference failed in the call to 'SelectMany'
- LINQ - type arguments cannot be inferred from the usage in a select
- Linq and the Equality Operator: Expression of type 'System.Int32' cannot be used for parameter of type 'System.Object'
- The LINQ expression node type 'Lambda' is not supported in LINQ to Entities
- Why can't the compiler infer the type for this select call?
- The 'TypeIs' expression with an input of type 'Domain.Entities.Request' and a check of type 'Domain.Entities.Base' is not supported
More Query from same tag
- Multiple requirements of a query
- NHibernate use .where() conditions in sql search or later using LINQ?
- Best way to remove multiple items matching a predicate from a .NET Dictionary?
- Flatten LINQ subselect so 1..n becomes one row
- LINQ Logic, Navigating to the ApplicationUser Identity table, roles and a business object called project
- Get Range Group Result from LINQ
- SQL Query union two tables, search multiple columns by multiple keywords
- LINQ Returning string array from DB.ExecuteQuery
- Distinct By LINQ The Best Way And quickly
- improve linq call to make one db call
- Error while sending a dropdown collection to a method accepting collection of Controls
- Injecting dependencies into Entity Framework entities and projects
- What's the return type of a LINQ query?
- LINQ - Sorting a custom list
- The nested query does not have the appropriate keys
- Sql query which returns multiple rows matching criteria
- Compare each string in datatable with that of list takes longer time.poor performance
- what would be the equivalent this for loop in linq
- Query to select worst-selling products
- How to write a linqu query with this foreach loop
- Casting substrings with linq into a list of object and than sorting it base on property in vb.net
- Is there a way that I can set more than one property in a list to "" or null at the same time with a .ForEach?
- Accessing a field of a class after a lambda expression
- How to convert linq results to HashSet or HashedSet
- linq query to return nested list for unique items
- init float array incrementing index value every x times with Linq
- Lambda expression for getting a table row and update the row in database
- Lambda and Nested Objects
- replace list value without looping
- filtering XML nodes containing a greater-than character in node text