xamarin - Xamarin Realm 退出时没有错误但没有结果
问题描述
我不知道如何调试这种行为。
我试图从我的领域数据库中检索一行,但是当我查询领域时,代码只是从方法中退出。
public User GetUser(int id)
{
User user = null;
try
{
if (RealmInstance.All<User>().Where(a => a.Id == id).Any())
{
user = RealmInstance.All<User>().Where(a => a.Id == id).First();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return user;
}
当我调试这个方法时,我看到调试器在这一行退出if(RealmInstance.All<User>().Where(a => a.Id == id).Any())
并且没有抛出错误,它只是出去而不继续执行。
这不是我第一次面对这种行为,我不知道如何强制 Realm 让我获取一些日志以查看附加的内容。
编辑1:
如果将我的代码拆分为此
var users = RealmInstance.All<User>();
var userFound = users.Where(a => a.Id == id);
//var userExist = userFound.Any(); //This cause the code to exit from method without exception
var userExist = userFound.Count() > 0; //This is OK sometimes, and other no. When it's work, it do not exit from method.
if (userExist)
{
user = users.Where(a => a.Id == id).First();
}
但我仍在寻找一种从 Realm 获得异常的方法
解决方案
推荐阅读
- html - Weglot 国家选择器不是真正的内联和不需要的悬停
- java - 拒绝对先前失败的类 java.lang.Class 重新初始化
android studio sqlite 数据库 - node.js - Cloud Build - 使用 exec 包装器连接到 Cloud SQL 代理 + 其他 GCP 资源的凭据错误
- swift - 在 SwiftUI 中“快速”导航会破坏绑定变量并阻止进一步导航
- javascript - 使用 Javascript 使 div 在点击时出现
- vue.js - URL 地址中的 Nuxtjs 区域
- sql - 带有窗口函数的多个 Sqlite3 连接
- hl7-fhir - 为 R4 患者添加扩展
- java - 如何通过其中的文本(Java)找到带有 Selenium 的按钮?
- python - 当元素是 Python-Selenium 中的链接时打印 url