- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 android 和 ormlite。我在初始化 ForeignCollection
时遇到问题。
我找到这个,初始化它:dao.getEmptyForeignCollection()
但对于 dao,我需要 DatabaseHelper
,对于 databasehelper,我需要 applicationContext,但在实体中我没有上下文。还有其他选择吗?
这就是代码,它是一对一的关系。类(class)团队:
@DatabaseField(canBeNull = true, foreign = true)
private Club club;
类(class)俱乐部:
@DatabaseField(canBeNull = true, foreign = true)
private ForeignCollection<Team> teams;
感谢帮助
最佳答案
你的问题不是关于外国收藏,而是关于如何ORMLite在 Android 下连接。所有这些都在文档中进行了解释:
您特别要求:
But for the dao, i need the
DatabaseHelper
, and for the database helper i need the applicationContext
, but in the entity i haven't a context. is there any other option?
在 Android 下,每个扩展 Activity
、ListActivity
、Service
和 TabActivity
的类 是一个上下文
。您可以从 online docs 查看类层次结构:
java.lang.Object
↳ android.content.Context
↳ android.content.ContextWrapper
↳ android.view.ContextThemeWrapper
↳ android.app.Activity
如果你看一下 Android example网站上提供的项目,您可以看到 Android 应用程序的连接方式:
您的主要 Activity
扩展 OrmLiteBaseActivity
public class HelloAndroid extends OrmLiteBaseActivity<DatabaseHelper> {
OrmLiteBaseActivity
中的 onCreate
方法使用 ORMLite OpenHelperManager
构建您的 DatabaseHelper
并将其自身作为上下文
:
OpenHelperManager.getHelper(this.getApplicationContext());
您使用 OrmLiteBaseActivity.getHelper()
方法来访问帮助程序以创建您的 DAO,这样您就可以将内容保存到数据库中。
关于android - 在哪里可以找到初始化 ORMLite 所需的 ApplicationContext?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10104152/
使用 ServiceStack.OrmLite,如果查询返回多个结果集,我如何访问所有结果集并将每个结果集分配给相应的 POCO。例如,我有一个包含以下代码的存储过程: SELECT * FROM U
首先,我是 ORMLite 的新手。我希望我的模型类有一个字段,它是一个字符串列表,最终将保存我的模型对象的标签列表。 我应该使用哪些 ORMLite 注释? 首先我不想拥有所有标签的表格,然后使用
在 Ormlite 中,是否可以在不编写实际 SQL 的情况下进行不区分大小写的查询? 例如,如果我正在寻找 列名 - “账户名” 并查询该列,如果我搜索“金融”,我想获得所有“金融”、“金融”、“金
我最近开始使用 ServiceStack 及其 ORMLite 框架。我在谷歌上搜索并浏览了源代码,但找不到任何相关内容。 使用 ORMLite 执行查询时,有没有办法选择特定的列? 类似的东西:Db
我正在寻找一种在 ormlite 中实现分页的好方法,我发现了另一个 question ,其中包含以下代码段: var data = db.Select(predicate).Skip((int) p
这是 Entity Framework : var department = _context.Departments .Include(dep => dep.Empl
我有一张 table CREATE TABLE [dbo].[ServiceTestCase]( [SSN] [int] IDENTITY(600000001,1) NOT NULL,
有没有办法用 servicestack/ormlite 预加载所有嵌套和子嵌套引用? public class Person { public int Id { get; set; }
继 this comment ,如何执行 ServiceStack OrmLite 查询来连接两个或多个表并从每个表中返回一些列? 使用 OrmLite Does_only_populate_Sele
我想知道是否可以查明 ORMLite 的 dao.createOrUpdate() 方法是否实际创建或更新了表行。有一个结果对象(CreateOrUpdateStatus),其中包含这些信息,但所有指
有什么方法可以返回 ServiceStack.OrmLite 中的表的子集吗? 像这样的东西: public class MyStuff { public Guid Id { get; set
使用 ormLite 我可以通过以下方式获取所有记录: myDao.queryForAll(); 如何只获取前 10 条记录而不是所有记录? 最佳答案 您必须使用 QueryBuilder 并设置限制
我正在 ServiceStack 的 OrmLite 中编写分页查询,选择页面范围内的总记录数和记录 ID。假设 query 是一些任意的 SqlExpression 选择一堆记录: var idQu
我正在努力用 ServiceStack 的 ORMLite 替换现有的“重型”商业 ORM。在重型 ORM 中,我们有能力 Hook “OnSaving”或“BeforeSaving”方法以在保存到数
我正在尝试 ServiceStack OrmLite,但现在我被这个异常难住了:A first chance exception of type 'System.NullReferenceExcept
我正在尝试 Ormlite。我发现当我插入一个带有 DateTime 属性的对象时,ormlite 应用它得到 -8:00 (我的时区是 +8)。应按字面意思插入时间。就我而言,它已经是 UTC。 但
我正在对现有的 SQL Server 数据库使用 OrmLite,该数据库已发布用于访问的存储过程。这些 SP 之一采用 3 个 int 参数,但期望其中一个或另一个为空。但是,没有任何参数被声明为可
我正在为数据可视化做一些查询,并依靠 GroupBy、Avg、Sum 和类似函数从数据库中获取良好的数据集。 我想在 ServiceStack OrmLite 中使用类似于 GroupBy 的东西。关
我希望使用 ORMLite 按多个别名表进行分组,但我似乎遇到了问题。 当在 SqlExpression 的 GroupBy 中使用具有匿名类型的 Sql.TableAlias 时,为 group b
这个周末我才第一次发现 ServiceStack,我觉得它非常棒。因此,我已经在将我所有的项目转换为它。然后我遇到了一个小障碍。 我找不到任何提到使用 OrmLite 首先从数据库开始然后将现有模式映
我是一名优秀的程序员,十分优秀!