zoukankan      html  css  js  c++  java
  • Linq 中的拼接条件

      public IQueryable<BBS_Theme> GetListPage(int PageSize, int PageIndex, NameValueCollection nvcParamWhere, NameValueCollection nvcorderby, ref int AllCount)
            {
    			#region where
    			var searchPredicate = PredicateExtensions.True<BBS_Theme>();
                if (nvcParamWhere != null)
                {
                    foreach (string key in nvcParamWhere)
                    {
                        string condition = string.Empty;
                        switch (key)
                        {
                            #region
    						case "ID":
                                condition = nvcParamWhere[key];
                                searchPredicate = searchPredicate.And(u => u.ID.Equals(condition));
                                break;
    						case "LableID":
                                condition = nvcParamWhere[key];
                                searchPredicate = searchPredicate.And(u => u.LableID.Equals(condition));
                                break;
    
    			
    						
                            default:
                                break;
    
                            #endregion
                        }
                    }
                }
    			#endregion
    			
    			#region queryable
                var linq = (from a in db.BBS_Theme
                            select a)
    						.Where(searchPredicate);
    			#endregion 
    			
    			#region orderby
                if (nvcorderby != null)
                {
                    foreach (string key in nvcorderby)
                    {
                        string condition = string.Empty;
    
                        switch (key)
                        {
    						case "ID":
                                condition = nvcorderby[key];
                                if(bool.Parse(condition))
    							{
                                	linq = linq.OrderBy(o=>o.ID);
    							}
    							else
    							{
                                    linq = linq.OrderByDescending(o => o.ID);
    							}
                                break;
    						//........省略n个case
    						
                            default:
                                break;
    
                        }
                    }
                }
    			#endregion
    			
    			AllCount = linq.Count();
                linq = linq.Skip(PageSize * (PageIndex - 1)).Take(PageSize);
                return linq;
            }
    
  • 相关阅读:
    线性反馈系统
    静磁场
    平面波的传播
    Partition does not end on cylinder boundary
    FFTW简介及使用
    EINTR、ERESTARTSYS和SIGINT
    凉面
    linux Shell编程
    Linux From Scratch [2]
    Linux From Scratch [1]
  • 原文地址:https://www.cnblogs.com/nanxiaoxiang/p/2849818.html
Copyright © 2011-2022 走看看