score:11
you are using selectmany
, which means project the individual items of another enumerable of enumerables. company.name
i presume is a string, which is a collection of char
s.
you probably want to just use select
given your expectations.
score:3
there were a few other answers, but i thought i'd include an explanation.
if you look at the msdn definition of a string, you'll see that it is implemented as an ienumerable<char>
:
[serializableattribute]
[comvisibleattribute(true)]
public sealed class string : icomparable,
icloneable, iconvertible, icomparable<string>, ienumerable<char>,
ienumerable, iequatable<string>
then, compare that to the definiton of selectmany:
projects each element of a sequence to an ienumerable and flattens the resulting sequences into one sequence
(there's a pretty good visual explanation here: http://www.codethinked.com/a-visual-look-at-the-linq-selectmany-operator)
since the selectmany
will treat the string
as an ienumerable<char>
object,
we can infer that the resulting collection from .selectmany(x => x.name)
will be an ienumerable<char>
made up of all of the characters contained within name
.
so, in this case, since you're really only looking for all of the name
strings contained within your a.charge.company
objects, you really just need to use select
:
var companynamelist = prop.chargeitems.select(a => a.charge.company.name).tolist();
score:4
this is because of selectmany, you need probably select here.
selectmany: projects each element of a sequence to an ienumerable and flattens the resulting sequences into one sequence.
so executing selectmany
you get ienumerable<char>
, after you call tolist()
, which projects it to a list<char>
Source: stackoverflow.com
Related Query
- why is my lambda expression being a character?
- Why can't you edit and continue debugging when there's a Lambda expression in the method?
- Lambda Expression for Many to Many realtionship in C# EF 5 Code First
- Why does passing an expression object to where returns a different result than typing the lambda expression?
- Why does lambda expression assume char instead of string
- How to write the same code using Lambda Expression
- How to write following code in lambda expression or linq?
- why gives error Expression cannot contain lambda expressions?
- ForEach loop with Lambda expression in Razor code MVC 5 For List<T>
- VS Code Coverage won't recognize only possible Expression Lambda Path
- Lambda expression with statement body error in previously working code
- Why in generated DataBaseManagerController table header is generated using lambda expression in ASP MVC 4
- Why Lambda expression returns System.Linq.Enumerable+WhereSelectEnumerableIterator`2 as a result
- Why the lambda expression change LEFT JOIN TO INNER JOIN When i put && condition?
- How to insert a record in lambda expression and possible way to shorten the length of code
- Retrieving Property name from lambda expression
- "A lambda expression with a statement body cannot be converted to an expression tree"
- An expression tree lambda may not contain a null propagating operator
- Cannot convert lambda expression to type 'string' because it is not a delegate type
- C# Pass Lambda Expression as Method Parameter
- "Or" equivalent in Linq Where() lambda expression
- Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
- How to write a VB.Net Lambda expression
- Pass a lambda expression in place of IComparer or IEqualityComparer or any single-method interface?
- What are Expression Trees, how do you use them, and why would you use them?
- LINQ: Passing lambda expression as parameter to be executed and returned by method
- Cannot convert lambda expression to type 'object' because it is not a delegate type
- Can you create a simple 'EqualityComparer<T>' using a lambda expression
- Like in Lambda Expression and LINQ
- What is the Efficiency and Performance of LINQ and Lambda Expression in .Net?
More Query from same tag
- how to discard changes made to all linq tables?
- add nested group by query Linq to property model class ASP.NET
- Read duplicate datarows from database into business objects and distinct them using LINQ
- Linq Query to display string from XML in a TextBox
- Issues on Win Host godaddy
- GroupBy method into C# based on SQL query
- How to build LINQ-query dynamically based on array of input arguments
- Something not quiet right with my linq statement binding to a listview
- order collection by date where some items dont have a value
- documentdb join with linq
- Linq-to-SQL in ASP.NET MVC using stored procedures
- totaling hours by month for split weeks using linq
- How to avoid duplicate records in c#
- EF Code First- Return Records from Many to Many Table
- Get maximum Count Lists Nested inside a list
- Cannot access child value on JValue in Azure Mobile App
- How do I cast the results of a LINQ query against my custom object implicitly?
- ASP.Net Linq Databinding not showing data as expected
- How to skip repeated ids from table and select remains using linq
- Linq or XSLT combine multiple variable elements into one
- LINQ/lambda: How can I query a DB table based on information from another table? (many to many relationship)
- Dynamic linq query that Contains ALL from another list
- EF Code First: Relationships with differing key names
- Linq query to select distinct record and count number of distinct record
- LINQ to SQL create query from string
- LINQ to EF returning all columns and not passing WHERE clause to server
- How to access data from multiple tables
- Mapping select query to an object makes an error in linq
- How to Convert SQL query consisting 'not in' into LINQ?
- The entity or complex type cannot be constructed in a LINQ to Entities query - using lambda expression