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();
var fields = entities
.SelectMany(e => e.fields)
.Where(f => f.FieldType.Id.Contains(fieldTypeId)
&& !string.IsNullOrEmpty(f.Data))
.ToList();