刚刚掌握RavenDB - 这很棒 - 但是我对查询有点困惑。我使用SaveChanges()方法运行foreach并使用Store()方法保存一些数据。
一旦我存储了这些信息,我需要引用这些信息来存储一些额外的信息(如果你在这一点上略微混淆,代码会说清楚,请不要担心!)但是当我参考信息时没有要找到的信息。
所以,首先我添加一些数据:
foreach (var development in developments)
{
Console.WriteLine(" - Working on Developmnent ID: " + development.devID);
Session.Store(new Domain.Development
{
Id = "D" + Convert.ToString(development.devID),
Name = development.devName,
Street = development.devStreet,
Town = development.devTown,
County = development.devCounty,
Postcode = development.devPostcode,
Country = development.devCounty,
Description = "",
Longitude = GeoData.Longitude(development.devPostcode),
Latitude = GeoData.Latitude(development.devPostcode)
});
}
现在,由于会话中可以运行的查询数量有限,我会检索整个数据集并存储在内存中:
var developmentList = from d in Session.Query<Domain.Development>()
select d;
现在,当我在此末尾添加一个断点时,没有找到数据。我是否需要创建另一个会话来检索此数据?
我也试过
var developmentList = Session.Query<Domain.Development>();
以下是我创建会话的代码:
internal static DocumentStore Store;
internal static IDocumentSession Session { get; set; }
internal <<Constructor>> ...
Store = new DocumentStore { ConnectionStringName = "RavenDB" };
Store.Initialize();
IndexCreation.CreateIndexes(Assembly.GetCallingAssembly(), Store);
Session = Store.OpenSession();
答案 0 :(得分:1)
不建议你这样做。默认情况下回到RavenDB的安全概念。
答案 1 :(得分:1)
如果您只是存储了这些值,为什么需要将它们保存到数据库并从数据库中重新加载它们?只需使用in memory collection即可。