RavenDB不存储我的新文档

时间:2017-09-19 22:26:08

标签: c# .net ravendb

这是我将新数据列表存储到文档的代码:

using (var session = DocumentStoreHolder.Store.OpenSession())
{

    //This list is used to put in the database -- Careful!!!
    List<classA> List_01 = new List<classA>();

    //This list is from database, used to compare with the new coming data. 
    //We will check with the list got from data.
    List<ClassA> List_02 = session.Query<classA>().ToList();

    //This uses the method Except to remove the duplicates between the new data 
    //and the current list of matches in database.Return data is the new match 
    //that is not existing in DB 

     List_01 = List_02.Except(List_00, new IdComparer()).ToList();
     foreach (classA data in List_01)
     {
         //Why does it not store data in DB?!?!?!?!?
         session.Store(data);
      }
     session.SaveChanges();
}

我将两个列表比较后。问题是会话似乎不存储我的数据。我不知道我的代码有什么问题。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

在您的代码中,您正在调用.Store(_match)。你的意思是打电话.Store(数据)?

另请注意,在调用.SaveChanges后,您的对象将位于数据库中。调用.Store分配ID并告诉Raven你想要存储它们,但是在调用.SaveChanges之前它不会生效。