Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linq "E;。。无法从用法中推断。”;如何将where和orderby表达式都插入到此sqlite查询中?_Linq_Sqlite_Mono_Xamarin.android - Fatal编程技术网

Linq "E;。。无法从用法中推断。”;如何将where和orderby表达式都插入到此sqlite查询中?

Linq "E;。。无法从用法中推断。”;如何将where和orderby表达式都插入到此sqlite查询中?,linq,sqlite,mono,xamarin.android,Linq,Sqlite,Mono,Xamarin.android,我一直在MonoDroid网站上关注,但在创建过滤和排序查询时遇到了问题。我想知道是否有人能解释一下我可能出了什么问题?我可能在做完全相反的事情 我得到一个错误: 无法从用法推断方法“ICanTalk.BusinessLayer.Services.WordServices.Find(System.Func,System.Func,bool,int,int)”的类型参数。尝试显式指定类型参数 在我的一个存储库中,我有以下代码,希望我所要做的有点清楚。我还无法构建它,但要测试它是否有效: pub

我一直在MonoDroid网站上关注,但在创建过滤和排序查询时遇到了问题。我想知道是否有人能解释一下我可能出了什么问题?我可能在做完全相反的事情

我得到一个错误:

无法从用法推断方法“ICanTalk.BusinessLayer.Services.WordServices.Find(System.Func,System.Func,bool,int,int)”的类型参数。尝试显式指定类型参数

在我的一个存储库中,我有以下代码,希望我所要做的有点清楚。我还无法构建它,但要测试它是否有效:

  public static IEnumerable<Word> Find<T,U>(Func<Word, bool> whereClause, Func<Word,U> orderBy, bool ascending, int show, int page)
  {
      int currentPage = page;
      int resultsPerPage = show;
      int skip = currentPage*show;

      var result = ascending
                       ? me.db.Find<Word>().Where(whereClause).OrderBy(orderBy).Take(resultsPerPage).Skip(skip)
                       : me.db.Find<Word>().Where(whereClause).OrderByDescending(orderBy).Take(resultsPerPage).Skip(skip);

      return result;

  }

这两种方法都是泛型的
Find
Find
——但在方法定义中似乎没有使用类型
t
T
是否应为类型
Word

U
按顺序使用一次,您在其他地方使用
bool
-这些用法中哪一个是错误的?

您是否可以尝试在定义中将
Word
替换为
T
,将
bool
替换为
U
(如果这是您的本意),然后在调用该方法时实际使用正确的类型调用它

var wordTest = WordServices.Find<Word>(x => x.ChildId == 3,
                                       x => x.AddedAt, 
                                       true, 5, 1);
var-wordTest=WordServices.Find(x=>x.ChildId==3,
x=>x.AddedAt,
对,5,1);
我几乎做对了,我把它精简到了最基本的部分,然后以自己的方式重新编写,并得出以下结论(如果您感兴趣,请与原始版本进行比较)

SQLiteDatabase.cs

(不是在最初的帖子中-我在我的泛型处理程序中将查询子句缩小到一个可重用的方法):

public IEnumerable Find(Func where子句、int resultsToSkip、int resultsToShow)
其中T:BusinessLayer.Contracts.IBusinessEntity,new()
{
锁(储物柜)
{
return Table().Where(Where子句).Skip(resultsToSkip).Take(resultsToShow.ToList();
}
}
WordRepository.cs

public static IEnumerable Find(Func where子句、int resultsToSkip、int resultsToShow)
其中T:BusinessLayer.Contracts.IBusinessEntity,new()
{
var result=me.db.Find(where子句、resultsToSkip、resultsToShow);
返回结果;
}
WordServices.cs

至此,我想知道为什么需要这么多层——我肯定会在早上进行重构。

public static IList Find(Func where子句、Func orderBy、bool升序、int show、int page)
{
int resultsToShow=show;
int resultsToSkip=show*(第1页);
var result=升序?WordRepository.Find(where子句、resultsToSkip、resultsToShow).OrderBy(OrderBy)
:WordRepository.Find(where子句、resultsToSkip、resultsToShow).OrderByDescending(orderBy);
返回result.ToList();
}
发起呼叫

var-wordTest1=WordServices.Find(x=>x.ChildId==1,x=>x.AddedAt,true,5,1);

嘿,谢谢你的回复。回过头来看,这有点令人困惑,实际上是hrrrm。U应该通过T的任何属性表示OrderBy。也就是说,U可以在OrderBy被添加的日期之前被T.AddedAt添加到OrderBy,或者T.ChildId或类似的东西。我现在已经缩小了它的规模,试图再次从底部开始构建它,看看是否可以让它工作!再次干杯
 var wordTest = WordServices.Find(x => x.ChildId == 3, x => x.AddedAt, true, 5, 1);
var wordTest = WordServices.Find<Word>(x => x.ChildId == 3,
                                       x => x.AddedAt, 
                                       true, 5, 1);
    public static IEnumerable<Word> Find<T>(Func<Word, bool> whereClause, int resultsToSkip, int resultsToShow)
        where T : BusinessLayer.Contracts.IBusinessEntity, new()
    {
        var result = me.db.Find<Word>(whereClause, resultsToSkip, resultsToShow);

        return result;
    }
    public static IList<Word> Find<T, U>(Func<Word, bool> whereClause, Func<Word, U> orderBy, bool ascending,  int show, int page)
    {
        int resultsToShow = show;
        int resultsToSkip = show * (page - 1);

        var result = ascending ? WordRepository.Find<Word>(whereClause, resultsToSkip, resultsToShow).OrderBy(orderBy)
                               : WordRepository.Find<Word>(whereClause, resultsToSkip, resultsToShow).OrderByDescending(orderBy);

        return result.ToList();
    }
   var wordTest1 = WordServices.Find<Word, DateTime>(x => x.ChildId == 1, x => x.AddedAt, true, 5, 1);