0

人物模型:

public class Person {
    public Int32  Id   { get; set; }
    public String Name { get; set; }
}

从数据库中查找人:

public List<Person> find()
{
    using (var db = new LiteDatabase(DatabasePathProvider.CacheLiteDbPath))
    {
        var col = db.GetCollection<Person>("Person");
        var list = col.FindOne(m => m.Name != null);

        return list;
    }
}

如代码所示,在数据库上执行查找查询时,堆栈跟踪会引发此异常:

  at System.Dynamic.Utils.ContractUtils.RequiresNotNull (System.Object value, System.String paramName) [0x00003] in <1ea41f79845a40618089713a1d9403c4>:0 
  at System.Linq.Expressions.Expression.Call (System.Reflection.MethodInfo method, System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1) [0x00000] in <1ea41f79845a40618089713a1d9403c4>:0 
  at LiteDB.BsonExpression.ParseSingleExpression (LiteDB.StringScanner s, System.Linq.Expressions.ParameterExpression root, System.Linq.Expressions.ParameterExpression current, System.Boolean isRoot) [0x0004c] in <a5ae904d7e2141da931e206893177173>:0 
  at LiteDB.BsonExpression.ParseExpression (LiteDB.StringScanner s, System.Linq.Expressions.ParameterExpression root, System.Linq.Expressions.ParameterExpression current, System.Boolean arithmeticOnly) [0x00000] in <a5ae904d7e2141da931e206893177173>:0 
  at LiteDB.BsonExpression.Compile (LiteDB.StringScanner s, System.Boolean pathOnly, System.Boolean arithmeticOnly) [0x00045] in <a5ae904d7e2141da931e206893177173>:0 
  at LiteDB.BsonExpression.Compile (System.String expression) [0x0003a] in <a5ae904d7e2141da931e206893177173>:0 
  at LiteDB.BsonExpression..ctor (System.String expression) [0x00010] in <a5ae904d7e2141da931e206893177173>:0 
  at LiteDB.Query.Run (LiteDB.CollectionPage col, LiteDB.IndexService indexer) [0x00055] in <a5ae904d7e2141da931e206893177173>:0 
  at LiteDB.LiteEngine+<Find>d__9.MoveNext () [0x000cd] in <a5ae904d7e2141da931e206893177173>:0 
  at LiteDB.LiteEngine+<Find>d__13.MoveNext () [0x001e4] in <a5ae904d7e2141da931e206893177173>:0 
  at LiteDB.LiteCollection`1+<Find>d__17[T].MoveNext () [0x000ba] in <a5ae904d7e2141da931e206893177173>:0 
  at System.Linq.Enumerable.TryGetFirst[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Boolean& found) [0x00045] in <1ea41f79845a40618089713a1d9403c4>:0 
  at System.Linq.Enumerable.FirstOrDefault[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x00000] in <1ea41f79845a40618089713a1d9403c4>:0 
  at LiteDB.LiteCollection`1[T].FindOne (System.Linq.Expressions.Expression`1[TDelegate] predicate) [0x0000d] in <a5ae904d7e2141da931e206893177173>:0 
  at UandUST.Cache.Cache+<Find>d__0.MoveNext () [0x000a0] in C:\Users\iMentor\source\repos\ust\UandUSTAppCenterGit\UandUST\UandUST\Cache\Cache.cs:35
4

1 回答 1

0

您未正确安装 litedb:

https://github.com/mbdavid/LiteDB/issues/896

似乎缺少这些 litedb 依赖项:

System.Reflection (>= 4.3.0)
System.Reflection.TypeExtensions (>= 4.3.0)

只需删除对 LiteDB 的旧引用并使用此 nuget 包安装它:

https://www.nuget.org/packages/LiteDB/

于 2019-08-20T10:09:22.310 回答