0
我想在ravendb中創建一個數據庫,我使用EnsureDatabaseExist()函數。我無法使用名稱空間Raven.Client.Extensions中的函數CreateDatabaseDocument(),並且我的c#代碼中的類爲public static class MultiDatabase {}。 vs2010中的Intellisense不顯示此功能。通過CreateDatabaseDocument()函數創建adatabase
我的代碼是:enter code here
public CreateDatabaseOpResult CreateDatabase(ConnectionOperationResult connection,string name)
{
DocumentDatabase database;
CreateDatabaseOpResult databaseOperationResult = new CreateDatabaseOpResult();
if (connection.IsOperationSuccessfull == true)
{
try
{
var doc = connection.documentStore.DatabaseCommands.ForDefaultDatabase();
var docId = doc.Get("Raven/Databases/" + name);
if (docId == null)
{
//static class
//multidatabase
connection.documentStore.DatabaseCommands.EnsureDatabaseExists(name);
}
else
{
databaseOperationResult.IsOperationSuccessfull = false;
throw new ArgumentException("Database already exists");
}
databaseOperationResult.IsOperationSuccessfull = true;
databaseOperationResult.database = database;
}
//and i want to use this function from
namespace Raven.Client.Extensions
{
///<summary>
/// Methods to create mutli tenants databases
///</summary>
public static class MultiDatabase
{
public static RavenJObject CreateDatabaseDocument(string name)
{
AssertValidName(name);
var doc = RavenJObject.FromObject(new DatabaseDocument
{
Settings =
{
{"Raven/DataDir", Path.Combine("~", Path.Combine("Tenants", name))}
}
});
doc.Remove("Id");
return doc;
}
thanks in advance...:)
非常感謝你.. 但是我怎樣才能從這個函數獲取數據庫對象。因爲我需要進一步處理這個數據庫對象... – 2012-04-17 06:43:56
調用EnsureDatabaseExists,然後從服務器獲取文檔,修改它,然後保存。 – 2012-04-17 07:59:59
它發出異常「無法加載一個或多個請求的類型」。documentStore.DatabaseCommands.EnsureDatabaseExists(name); databaseOperationResult.IsOperationSuccessfull = true; Raven.Database.Config.InMemoryRavenConfiguration memoryRaven = new Raven.Database.Config.InMemoryRavenConfiguration() { DatabaseName = name, }; DocumentDatabase database = new DocumentDatabase(memoryRaven); //在上一條語句中,它引發異常。請幫助我 – 2012-04-18 09:01:39