MvvmCross社区SQLite插件 - NotSupportedException

时间:2014-02-10 19:46:50

标签: c# android sqlite xamarin mvvmcross

我正在开发一个带有SQLite插件的Xamarin应用程序(目前适用于Android)。 我使用db添加的第一个方法之一是:

public ItemType FindItemById<ItemType> (int id) where ItemType : IDataItem, new()
{
    return connection.Table<ItemType> ().Where (item => item.id == id).FirstOrDefault ();
}

调用方法时抛出以下异常:

InnerException was NotSupportedException: Cannot compile: Parameter
      at Community.SQLite.TableQuery`1[Prototype.Core.Services.DataStore.Product].CompileExpr (System.Linq.Expressions.Expression expr, System.Collections.Generic.List`1 queryArgs) [0x00000] in <filename unknown>:0 
  at Community.SQLite.TableQuery`1[Prototype.Core.Services.DataStore.Product].CompileExpr (System.Linq.Expressions.Expression expr, System.Collections.Generic.List`1 queryArgs) [0x00000] in <filename unknown>:0 
  at Community.SQLite.TableQuery`1[Prototype.Core.Services.DataStore.Product].CompileExpr (System.Linq.Expressions.Expression expr, System.Collections.Generic.List`1 queryArgs) [0x00000] in <filename unknown>:0 
  at Community.SQLite.TableQuery`1[Prototype.Core.Services.DataStore.Product].CompileExpr (System.Linq.Expressions.Expression expr, System.Collections.Generic.List`1 queryArgs) [0x00000] in <filename unknown>:0 
  at Community.SQLite.TableQuery`1[Prototype.Core.Services.DataStore.Product].GenerateCommand (System.String selectionList) [0x00000] in <filename unknown>:0 
  at Community.SQLite.TableQuery`1[Prototype.Core.Services.DataStore.Product].GetEnumerator () [0x00000] in <filename unknown>:0 
  at System.Collections.Generic.List`1[Prototype.Core.Services.DataStore.Product].AddEnumerable (IEnumerable`1 enumerable) [0x00000] in <filename unknown>:0 
  at System.Collections.Generic.List`1[Prototype.Core.Services.DataStore.Product]..ctor (IEnumerable`1 collection) [0x00000] in <filename unknown>:0 
  at System.Linq.Enumerable.ToList[Product] (IEnumerable`1 source) [0x00000] in <filename unknown>:0 
  at Community.SQLite.TableQuery`1[Prototype.Core.Services.DataStore.Product].FirstOrDefault () [0x00000] in <filename unknown>:0 
  at Prototype.Core.Services.DataStore.Repository.FindItemById[Product] (Int32 id) [0x0000e] in e:\Projects\Mobile\AppMaster\crossplatform\Prototype\Prototype.Core\Services\DataStore\Repository.cs:55 
  at Prototype.Core.ViewModels.SingleProductViewModel.Init (Prototype.Core.ViewModels.Navigation navigation) [0x00022] in e:\Projects\Mobile\AppMaster\crossplatform\Prototype\Prototype.Core\ViewModels\SingleProductViewModel.cs:28 

有人可以解释我做错了什么吗?

添加了:

这与此方法的“通用性”有关。当我这样写时(通常的非通用方法):

public Product FindProductById (int id)
{
    return connection.Table<Product> ().Where (product => product.id == id).Select (product => product).FirstOrDefault ();
}

它开始工作......它可能是SQLite插件中的错误吗?

0 个答案:

没有答案