通过Create Database Document()函数创建数据库

时间:2012-04-17 05:01:03

标签: database c#-4.0 nosql ravendb

我想在ravendb中创建一个数据库,我使用了EnsureDatabaseExist()函数。我无法使用命名空间Raven.Client.Extensions中的CreateDatabaseDocument()函数,而类是我的c#代码中的公共静态类MultiDatabase {}。 vs2010中的智能感知未显示此功能。

我的代码是: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...:)

1 个答案:

答案 0 :(得分:1)

CreateDatabase是一个内部方法,只返回数据库文档EnsureDatabaseExist使用此方法,并且如果该文档不存在,也会存储该文档。

您应该使用EnsureDatabaseExist方法。