【问题标题】:IEnumerable filterIEnumerable 过滤器
【发布时间】:2014-07-21 21:31:39
【问题描述】:

如何添加过滤器以便只返回 26-30 的关系类型 ID?

public IEnumerable<SelectListOptions> GetRelationshipTypes()
{
    return (from q in unitOfWork.GenericRepository<tlkpRelationshipType>().Get()
            select new SelectListOptions
            {
                Value = q.RelationshipTypeID.ToString(),
                Label = q.RelationshipType
            }
            ).ToList();
}

【问题讨论】:

  • 请不要给以上问题打负分。这可能会永久阻止他提问。

标签: c# linq ienumerable


【解决方案1】:

像这样使用where 子句:

public IEnumerable<SelectListOptions> GetRelationshipTypes()
{
    return (from q in unitOfWork.GenericRepository<tlkpRelationshipType>().Get()
            where q.RelationshipTypeID >= 26 && q.RelationshipTypeID <= 30
            select new SelectListOptions
            {
                Value = q.RelationshipTypeID.ToString(),
                Label = q.RelationshipType
            }
            ).ToList();
}

【讨论】:

    【解决方案2】:
    return (from q in unitOfWork.GenericRepository<tlkpRelationshipType>().Get()
            where q.RelationshipTypeID >= 26
            where q.RelationshipTypeID <= 30
            select new SelectListOptions
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-05
      相关资源
      最近更新 更多