- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
因此,我尝试在 UserDatabse.cs 类中使用此方法检索特定日期的“Sugar”类的实例:
public List<Sugar> GetSugarDate(DateTime dt)
{
var bld = database.Table<Sugar>().Where(mi => mi.Time.Date == dt.Date).ToList();
return bld;
}
*请记住,应用程序目前没有任何 Sugar 实例,因此日期比较是在空日期和实际日期之间进行的。我认为这是导致错误的原因,任何解决方案将不胜感激。
在另一个类中调用此方法是这样的:
DateTime Time = DateTime.Now;
ObservableCollection<Image> Sugar_Count = new ObservableCollection<Image>();
Image s = new Image();
s.Source = "drawable/soda.png";
var xa = App.Database.GetSugarDate(Time);
Sugar.cs 类定义如下:
public class Sugar
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public DateTime Time { get; set; }
public int DrinkCount { get; set; }
public Sugar()
{
Time = DateTime.Now;
DrinkCount = 0;
}
}
现在得到的错误如下:
System.NotSupportedException: Member access failed to compile expression at SQLite.TableQuery'1[T].CompileExpr(System.Linq.Expressions.Expression expr, System.Collections.Generic.List'1[T]queryArgs)[0x006cc]in <9b4aaa861238418bec74a2ddde70f09>:0 at SQLite.TableQuery'1[T].CompileExpr(System.Linq.Expressions.Expression expr, System.Collections.Generic.List'1[T]queryArgs)[0x0009d]in <9b4aaa861238418bec74a2ddde70f09>:0 at SQLite.TableQuery'1[T].CompileExpr(System.Linq.Expressions.Expression expr, System.Collections.Generic.List'1[T]queryArgs)[0x0005f]in <9b4aaa861238418bec74a2ddde70f09>:0 at SQLite.TableQuery'1[T].CompileExpr(System.Linq.Expressions.Expression expr, System.Collections.Generic.List'1[T]queryArgs)[0x00008]in <9b4aaa861238418bec74a2ddde70f09>:0 atSystem.Collections.Generic.List'1[T]..ctor(System.Collections.Generic.IEnumerable'1[T]collection)[0x00062] in /Users/builder/jenkins/workspace/xamarin-android/external/mono/mcs/class/referencesource/generic/list.cs:98 .....
错误发生在该特定行:
var bld = database.Table<Sugar>().Where(mi => mi.Time.Date == dt.Date).ToList();
我哪里出错了?
最佳答案
这部分表达式无法翻译为 SQL。
mi => mi.Time.Date
您可以尝试使用:
var bld = database.Table<Sugar>().ToList().Where(mi => mi.Time.Date == dt.Date).ToList();
Accessing to the Date part of a
DateTime
column (mi.Time.Date
) can not be translated to SQL using Linq, for this reason, your statement failed initially. So, usingToList
fetches all records in memory allowing us to query with Linq to Object method not Linq to SQLite.
关于sqlite - 日期比较时出现错误 : System. NotSupportedException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45423235/
目前,我有一个在我的 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
我是一名优秀的程序员,十分优秀!