从iqueryable获取选定的列

时间:2018-10-15 12:01:00

标签: c# entity-framework

如何从IQueryable对象返回fieldList

// fieldList="Code,Name";
var result = from Activity in query
select new 
{
  Code = Activity.Code,
  Name = Activity.Name,
  StatusCode = Activity.ClaimStatus.Name
};

1 个答案:

答案 0 :(得分:0)

DTO

 public class CustomDto
        {
            public string Code { get; set; }
            public string Name { get; set; }
            public string StatusCode { get; set; }

        }

转换为Dto

    var result = items.AsQueryable().Select(x => new CustomDto()
        {
            Code = x.Code,
            Name = x.Name,
            StatusCode = x.ClaimStatus
        }).ToList();