Linq查询:无法转换类型IEnumerable< string>将.ToString()更改为(string)的字符串 [英] Linq Query : Cannot convert type IEnumerable<string> to string changing .ToString() to (string)
问题描述
我有一个包含的linq查询
select new Project()
{
Manager = list.Employee.Select(x => x.Manager).ToString()
}).ToList();
这很简单,但我最终并没有得到数据...
我得到System.Linq.Enumerable+WhereSelectListIterator<Flex.Data.Systems,System.String>
的经理"的值
所以我以为我会改成(string)
而不是.ToString()
,但这不起作用
select new Project()
{
Manager = (string)list.Employee.Select(x => x.Manager)
}).ToList();
给我错误消息
无法将类型'System.Collections.Generic.IEnumerable'转换为'string'
您希望Manager
是什么,一个用逗号分隔的值列表的string
还是List<string>
/String[]
? >
字符串:
Manager = string.Join(",",list.Employee.Select(x => x.Manager))
收藏:
Manager = list.Employee.Select(x => x.Manager).ToList()
// or
Manager = list.Employee.Select(x => x.Manager).ToArray()
I have a linq query that contains
select new Project()
{
Manager = list.Employee.Select(x => x.Manager).ToString()
}).ToList();
This COMPILES, but I don't end up with the data...
I get value for "Manager" of System.Linq.Enumerable+WhereSelectListIterator<Flex.Data.Systems,System.String>
So I thought I would change to (string)
instead of .ToString()
but this does not work
select new Project()
{
Manager = (string)list.Employee.Select(x => x.Manager)
}).ToList();
Gives me the error message
Cannot convert type 'System.Collections.Generic.IEnumerable' to 'string'
What do you want Manager
to be, a string
with a comma separated list of values or a List<string>
/String[]
?
string:
Manager = string.Join(",",list.Employee.Select(x => x.Manager))
collection:
Manager = list.Employee.Select(x => x.Manager).ToList()
// or
Manager = list.Employee.Select(x => x.Manager).ToArray()
这篇关于Linq查询:无法转换类型IEnumerable< string>将.ToString()更改为(string)的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!