コード例 #1
0
        public MongoDataContext(string connectionNameOrString)
        {
            Contract.Requires <ArgumentNullException>(!string.IsNullOrWhiteSpace(connectionNameOrString));

            // If it's a name, we lookup config setting
            var connSettings = ConfigurationManager.ConnectionStrings[connectionNameOrString];

            if (connSettings != null && !string.IsNullOrWhiteSpace(connSettings.ConnectionString))
            {
                connectionNameOrString = connSettings.ConnectionString;
            }

            _db = GetDatase(connectionNameOrString);

            _roleCol            = _db.GetCollection <Role>(Role.GetCollectionName());
            _userCol            = _db.GetCollection <MembershipAccount>(MembershipAccount.GetCollectionName());
            _oAuthTokenCol      = _db.GetCollection <OAuthToken>(OAuthToken.GetCollectionName());
            _oAuthMembershipCol = _db.GetCollection <OAuthMembership>(OAuthMembership.GetCollectionName());

            // Check that we can connect to MongoDB server -- will throw an exception that should be caught in provider init
            _roleCol.EnsureUniqueIndex(x => x.RoleName);
        }