从列表返回值的问题

时间:2014-02-19 18:29:46

标签: c# asp.net c#-5.0

我在ASP.Net上有一个C#方法,它将数据填充到List:

public ICollection<Book> SelectFilteredBooks(){
 using (APPEntities entities = new APPEntities()) {
   try{
   FilterItemList list = (FilterItemList)HttpContext.Current.Session["FilterList"];
          if (list != null)
             {
               Dictionary<String, Object> parameters = new Dictionary<String, Object>();
               String whereParam = FilterItemList.WhereParameter(list.ItemList, "it", ItemType.Book, parameters);
                  if (!String.IsNullOrEmpty(whereParam))
                      {
                         var allResults = entities.BookS.Where(whereParam);
                         foreach (KeyValuePair<string, Object> kvp in parameters)
                          {
                   allResults.Parameters.Add(new ObjectParameter(kvp.Key, kvp.Value));                                 }

                     return allResults.ToList<Book>().ConvertAll(d => new Need { TITLE = d.TITLE.ToLower() });
                           }
                     }
                 }
                 catch (Exception e)
                 {
                      Debug.WriteLine(e.Message);
                 }
                 return entities.BookS.ToList();
             }
         } 

现在我的问题出现在allResults.ToList<Book>().ConvertAll(d => new Need { TITLE = d.TITLE.ToLower() });上,它只返回TITLE列值。如果还有其他一点可以将价值转换为低价,请告诉我吗?感谢

2 个答案:

答案 0 :(得分:1)

你不能这样写:

 var list = allResults.ToList<Book>()
 list.ForEach(d => d.TITLE = d.TITLE.ToLower());
 return list;

答案 1 :(得分:0)

尝试在不同的地方进行转换:

allResults.Parameters.Add(new ObjectParameter(kvp.Key, kvp.Value.ToString().ToLower()));