我在 ravendb 中创建了一个文档。使用 session.advanced.getmetadata(见代码),我在元数据中为 Raven-Entity-Name 命名,之后我在同一个函数中删除了该文档。然后我看到集合也被删除了。如果我手动删除文档raven studio 然后集合保留在数据库中。即使代码部分没有文档,集合如何持续存在?提前致谢 !!
我的 C# 代码是:
public CreateCollectionResult CreateCollection(string databaseName, string collectionName)
{
CreateCollectionResult createCollectionResult = new CreateCollectionResult();
Collection collection1234 = new Collection();
try
{
using (var session = documentStore.OpenSession(databaseName))
{
Guid guid = new Guid("12345678-1111-1111-2222-000000000000");
session.Store(collection1234, guid, "april-Days/10");
session.Advanced.GetMetadataFor<Collection>(collection1234)[Constants.RavenEntityName] = collectionName;
//session.Delete<Collection>(collection1234);
session.SaveChanges();
createCollectionResult.IsOperationSuccessfull = true;
}
}
//exception if database not found
catch (InvalidOperationException ex)
{
createCollectionResult.IsOperationSuccessfull = false;
createCollectionResult.Error = ex;
}
return createCollectionResult;
}