【发布时间】:2018-03-01 00:57:11
【问题描述】:
假设我正在存储一个新文档而没有指定 id,因此它使用 raven 自动文档,那么我将如何检索该 id 以立即使用?
League league = new League(){Name = "League1"};
RaventSession.Store(league);
Division division = new Division(){ Name = "Division1",
LeagueId = //need league id for this property
【问题讨论】:
-
除了接受答案的建议外,您可以这样做的一种方法是在您的 League 对象上拥有一个 .Id 属性。调用 .Store 后,它将被填充。
-
是的,我以前使用过这种方法,但我想避免自己分配 id。
-
澄清一下,当您调用 .Store 时,.Id 将自动为您填充。
-
啊我明白了,谢谢犹大
标签: ravendb