从 List<List<T>> 中提取数据

问题描述 投票:0回答:1
class FieldType
{
    string Id {get; set;}
    string dataType {get;set;}
}


class Field
{ 
    int fId{get;set;} 
    string fName{get;set;}
    FieldType fType{get;set;}
    string data;
}

class Entity
{
    int eId{get;set;}
    string eName{get;set;}
    List<Field> fields{get;set;}
}
List<Entity> entities = some entities;

现在,从实体列表中,我希望字段数据位于具有某些条件的字符串列表中。如下所示,但它给了我列表>

var fields = entities.Select(entity => entity.Fields.Where(field => field.FieldType.Id.Contains(fieldTypeId) && !string.IsNullOrEmpty(field.Data as string))
                                                .Select(data => data.Data as string)
                                                .ToList()).ToList();
c# .net entity-framework linq c#-4.0
1个回答
0
投票
var fields = entities
    .SelectMany(e => e.fields)
    .Where(f => f.FieldType.Id.Contains(fieldTypeId)
             && !string.IsNullOrEmpty(f.Data))
    .ToList();
© www.soinside.com 2019 - 2024. All rights reserved.