日期:2014-05-20  浏览次数:21214 次

【求助】下面的Linq语句要怎么改,提示“无法从用法中推导出方法xx的类型实参”
C# code

public static List<ReTailerSalesDataInfo> GetRetailerSalesData<TKey>(int pageSize, int pageIndex,
 Expression<Func<PublisherSalesDaily, TKey>> orderBy, bool isOrderByDescending,
Expression<Func<PublisherSalesDaily, bool>> condition)
        {
            Entity.EntitesDataContext db = new EntitesDataContext(Business.Entities.Config.Default.ConnectionString);
            try
            {
                IQueryable<ReTailerSalesDataInfo> q = from sf in db.RetailerSalesFailedRows
                                                      from si in db.RetailerSalesInfoRows
                                                      where sf.Retailer == si.Retailer
                                                      select new ReTailerSalesDataInfo
                                                      {
                                                          Retailer = sf.Retailer,
                                                          ISBN = sf.ISBN,
                                                          Date = sf.Date,
                                                          SoldCount = si.Quantity,
                                                          ReturnedCount = sf.Quantity,
                                                          SoldMoney = si.SellPrice * si.Quantity,
                                                          ReturnedMoney = Convert.ToDecimal(sf.Quantity ?? "0") * Convert.ToDecimal(sf.SellPrice ?? "0")
                                                      };
                var result=q.GetEntitysByPage(pageSize, pageIndex, orderBy, isOrderByDescending, condition);
/*错误    38    无法从用法中推导出方法“System.Collections.Generic.ExtensionEnumerable.GetEntitysByPage<TEntity,TKey>(System.Linq.IQueryable<TEntity>, int, int, System.Linq.Expressions.Expression<System.Func<TEntity,TKey>>, bool, System.Linq.Expressions.Expression<System.Func<TEntity,bool>>)”的类型实参。请尝试显式指定类型实参。    E:\xdq\Desktop\MyWorkSpace\SourceCode\BusinessTier\SalesData.cs    3338    28    Clochase.eBound.BusinessTier
*/
                return result.ToList();
/*
错误    39    无法从用法中推导出方法“System.Linq.Enumerable.ToList<TSource>(System.Collections.Generic.IEnumerable<TSource>)”的类型实参。请尝试显式指定类型实参。    E:\xdq\Desktop\MyWorkSpace\eBound\SourceCode\Clochase.eBound\Clochase.eBound.BusinessTier\SalesData.cs    3339    24    Clochase.eBound.BusinessTier
*/
            }
            catch (Exception exp)
            {
                return new List<ReTailerSalesDataInfo>();
            }
            finally
            {
                if (db != null)
                    db.Dispose();
            }
        }
//ReTailerSalesDataInfo类//自己定义的,非dbml生成
         public class ReTailerSalesDataInfo
        {
            public string Retailer { get; set; }
            public string ISBN { get; set; }
            public string Date { get; set; }
            public int? SoldCount { get; set; }
            public string ReturnedCount { get; set; }
            public decimal? SoldMoney { get; set; }
            public decimal ReturnedMoney { get; set; }
        }
//GetEntitysByPage方法
public static IQueryable<TEntity> GetEntitysByPage<TEntity, TKey>(this IQueryable<TEntity> source,
           int pageSize, int pageIndex,
           Expression<Func<TEntity, TKey>> orderBy, bool isOrderByDescending,
           Expression<Func<TEntity, bool>> condition) where TEntity : class
        {
            IQueryable<TEntity> results = source;
            if (condition != null)
                results = results.Where(condition);
            if (orderBy != null)
            {
                if (isOrderByDescending)
                    results = results.OrderByDescending(orderBy);
                else
                    results = results.OrderBy(orderBy);
            }
            results = results.Skip(pageIndex * pageSize).Take(pageSize);
            return results;
        }