我想修改LINQ查询,选择一些属性到一个数组,但我在努力实现它的一部分。LINQ选择到阵列
toRun.AddRange(entity.Properties
.Select(property => property.PrimaryField)
.Select(field => new { field, entity = entity.EntityName, table = field.Table, key = entity.EntityIdField })
我需要这个修改,这样如果第二个名为SecondaryField的属性不是null或空字符串,它将被添加到第一个Select语句的结果中。
例如,如果entity.Properties包含:
Property { PrimaryField = "a", SecondaryField = "b" },
Property { PrimaryField = "c", SecondaryField = "" }
我想第一个SELECT语句返回:
{ "a", "b", "c" }
得到任何帮助的感谢。
所以,你希望所有PrimaryFields的列表,而不是空或空所有SecondaryFields? – bixarrio
无论你的标题和你的问题不清楚的,我实在不明白的代码块和输出之间的关系,但你要找的东西像'.SelectMany(P =>新的[] {p.PrimaryField,P .SecondaryField)。凡(p =>!string.IsNullOrWhitespace(p))'? – CodeCaster
@CodeCaster这就是我的想法。 –