2016-03-21 40 views
0

有人能告诉我如何返回IQueryable<T>如何返回IQueryable <T>

我越来越:

无法隐式转换类型System.Linq.IQueryable<object>System.Linq.IQueryable<TType>。一个显式转换存在(被 缺少强制转换?)

预先感谢您

代码:

public IQueryable<TType> ExecuteScript<TType>(string script, object parameters) where TType : class, new() 
{ 
     string typeName = String.Empty; 

     LuaScript lScript = LuaScript.Prepare(script); 
     var lLScript = lScript.Load(Context.Server()); 

     //Converts returned result into a string array. 
     var result = (string[])lLScript.Evaluate(Context.Database(), parameters); 

     if (result.Any()) 
     { 
      _dataValue = new SortedDictionary<string, string>(); 
      int i=0; 

      while(i < result.Count()) 
      { 
       _dataValue.Add(result[i], result[i+=1]); 
       i++; 
      } 
     } 

     IQueryable<object> query = _dataValue.AsQueryable().Select(r => r.Value);    

     return query;      
    } 
+0

你为什么要返回IQueryable的''?数据在内存中,为什么不让它成为'IEnumerable '?调用'.AsQueryable()'的原因极其有限。 – Enigmativity

回答

0

您尝试从返回IQueryable<object>

IQueryable<object> query = _dataValue.AsQueryable().Select(r => r.Value);    
return query; 

但函数返回类型为IQueryable<TType>,从:

public IQueryable<TType> ExecuteScript<TType>(string script, object parameters) where TType : class, new() 

尝试:

IQueryable<TType> query = _dataValue.AsQueryable().Select(r => r.Value);    
return query; 
相关问题