MyMongodb.MongoData/NoSql/MongodbBase.cs
(开头部分) 5KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using MongoDB.Bson;
using MongoDB.Driver;
using MyMongodb.Entity;
using MyMongodb.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace MyMongodb.Data.NoSql
{
public class MongodbBase<T> where T : IMongoEntity
{
public static IMongoDatabase db = null;
private static IMongoCollection<T> collection;
private static MongodbConfig Config = null;
private static object Lock = new object();
private static object Lock_Service = new object();
private static List<MongoServerAddress> Servers = new List<MongoServerAddress>();
private static MongoUrlBuilder bldr = new MongoUrlBuilder();
protected void init(string DbName)
{
try
{
if (db != null)
{
collection = db.GetCollection<T>(typeof(T).Name);
return;
}
if (Config == null)
{
lock (Lock)
{
if (Config == null)
{
Config = ConfigManager.ServiceSettings.mongodbs.Where(p => p.DBName == DbName).FirstOrDefault();
}
}
}
if (Servers == null | !Servers.Any())
{
lock (Lock_Service)
{
if (Servers == null | !Servers.Any())
{
//Servers.Add(new MongoServerAddress(Config.Host));
Servers.Add(new MongoServerAddress("http://localhost:27017/"));
}
}
}
if (Config == null)
{
throw new Exception("不存在數據庫未:" + DbName + "的配置對象,請檢查");
后面还有 123 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
