- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在使用 C# 和 SQLite 编写 Windows 商店应用程序。在这种情况下,我遇到了一个问题,我为此寻找了解决方案。但我没有运气。问题是我想从表中删除一条记录。我的 table 是这样的
class DocumentRecord
{
[PrimaryKey, AutoIncrement]
public int dID { get; set; }
public string dName { get; set; }
public string dDescription { get; set; }
public byte[] dImage { get; set; }
public int uID { get; set; }
public string dTextData { get; set; }
public DateTime dCreatedDate { get; set; }
public DateTime dUpdatedDate { get; set; }
}`
我的删除方法如下:
private async void btnDelete_Click(object sender, RoutedEventArgs e)
{
//confirmation();
SQLiteAsyncConnection dbconn = new SQLiteAsyncConnection("Data.db");
var DeleteItem = await dbconn.Table<DocumentRecord>().Where(x => x.dName == (App.Current as App).documentName).FirstOrDefaultAsync();
if (DeleteItem != null)
{
await dbconn.DeleteAsync(DeleteItem);
var dlge = new MessageDialog("You successfully deleted a document !");
await dlge.ShowAsync();
}
}
我发现了如下所示的错误:
System.NotSupportedException: Cannot compile: TypeAs at SQLite.TableQuery`1.CompileExpr(Expression expr, List`1 queryArgs)
at SQLite.TableQuery`1.CompileExpr(Expression expr, List`1 queryArgs)
at SQLite.TableQuery`1.CompileExpr(Expression expr, List`1 queryArgs)
at SQLite.TableQuery`1.GenerateCommand(String selectionList)
at SQLite.TableQuery`1.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at SQLite.TableQuery`1.FirstOrDefault()
at SQLite.AsyncTableQuery`1.<FirstOrDefaultAsync>b__6()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at MMUD.LoadFlyout.<btnDelete_Click>d__6.MoveNext()
最佳答案
错误在这一行:
var DeleteItem = await dbconn.Table<DocumentRecord>().Where(x => x.dName == (App.Current as App).documentName).FirstOrDefaultAsync();
这里的问题是您传递给 Where
方法的 lambda 表达式是 SQLite LINQ 驱动程序无法弄清楚如何处理的东西。
为了解决这个问题,您需要从外部获取值并将其作为简单的字符串变量引用传入,如下所示:
string documentName = (App.Current as App).documentName;
var DeleteItem = await dbconn.Table<DocumentRecord>().Where(x => x.dName == documentName).FirstOrDefaultAsync();
生成的 lambda 表达式对于 SQLite 来说足够简单,可以从中生成 SQL 表达式。
关于c# - System.NotSupportedException : Cannot compile: TypeAs At SQLite. 表查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34711506/
目前,我有一个在我的 Mac 上运行的服务,该服务是用 C# 编写的,位于 usr/local/program。该服务能够通过根据服务器版本号检查版本号来检测何时需要更新。更新方法已运行,但是当它尝试
我们有一个下游系统,一个 ERP 系统,它可以通过 SOAP 公开其表。它发布的 Web 服务通常具有 Create、Update 和 Delete 方法。然后我们使用 svcutil 生成代理,包括
我在 Windows 商店应用程序中处理 SQLite。我正在使用更新表中的值 var tagPage = db.QueryAsync("UPDATE MyModel SET Tag =2 WHERE
我一直在努力使用 Moq 作为模拟框架并复制了一些非常简单的示例代码。我一定在这里遗漏了一些非常愚蠢的东西。它在 Setup 调用上抛出 NotSupportedException,即使它指向 Ret
为什么会抛出 System.NotSupportedException? string foo(string f) { return f; } string bar = ""; var item =
我开始遇到这个非常奇怪的问题,该应用程序在 iOS 模拟器上运行良好,但是当我在设备上启动它时,它显示登录屏幕,但在登录后,它崩溃并显示“不支持操作” “异常(exception)。堆栈跟踪是完全不可
有谁知道有什么方法可以克服 NotSupportedException?我有一个针对用户的方法: public virtual bool IsAbove(User otherUser) {
我正在对使用 IMemoryCache 的 ClientService 进行单元测试界面: 客户端服务.cs: public string Foo() { //... code
因此,我尝试在 UserDatabse.cs 类中使用此方法检索特定日期的“Sugar”类的实例: public List GetSugarDate(DateTime dt) { var
我需要在忽略大小写的情况下从数据库上下文中查找项目,但无法正常工作,到目前为止我尝试过的是: var interestingItem = ctx.MyItems.FirstOrDefault(x =>
我有这条路径可以根据日期和时间保存 Excel 工作表。它正在显示System.NotSupportedException 什么是正确的格式? string strpath = Server.M
我正在尝试返回状态更新列表,该列表按插入日期降序排列。此列表显示在局部 View 中,因此我无法使用 Controller 对列表进行排序。解决方案是创建一个包含以下代码的服务类: var Statu
如果我有一个尚未实现基类提供的函数的子类,我可以覆盖该函数并让它抛出一个NotSupportedException。有没有办法为此生成编译时错误以避免仅在运行时命中它? 更新:我不能使基类抽象。 最佳
我有一个如下所示的查询: var caseList = (from x in context.Cases where allowedCaseIds.Contains(x => x.C
我正在创建客户端-服务器应用程序。 服务器代码: public sealed class SslTcpServer { static X509Certificate serverCertifi
我正在构建一个本地化目录,但遇到了设计难题。现在,目录存储一个 Dictionary存储翻译,其中 IString可以是两种类型:Singular或 Plural .这是 IString 的简化版本:
我一直在做一个需要通过 JSON 文件保存和加载数据的项目。此 JSON 文件包含其他对象的各种列表。但是,当我继续反序列化文件时,会发生这种情况: System.NotSupportedExcept
File.ReadAllText 似乎有问题,因为即使目标文件存在,它也会返回“NotSupportedException”。无论将什么放入参数中,它都会不断抛出相同的异常。 using System
您能否帮助解决此错误的问题或说明如何以不同的方式完成此操作。谢谢! 我的任务是输出结果(集合),其中包含每个实体的注释。如果用户在选中它。 protected Expression > MapToB
LINQ 到 EF: db.ReadonlyQuery() .Select(t => new ACurrentDayInfo { OrderI
我是一名优秀的程序员,十分优秀!