client.GetServer() 已弃用,我该如何修复它?
client.GetServer() deprecated , how can I fixed it?
我的代码块:
public StudentsUnitOfWork()
{
var connectionString = ConfigurationManager.AppSettings["MongoDBConectionString"];
var client = new MongoClient(connectionString);
var server = client.GetServer();
var databaseName = ConfigurationManager.AppSettings["MongoDBDatabaseName"];
_database = server.GetDatabase(databaseName);
}
VS 2015 我得到 client.GetServer() deprecated , how can I fixed it?
在我改用这个之后:
public StudentsUnitOfWork()
{
var connectionString = ConfigurationManager.AppSettings["MongoDBConectionString"];
var client = new MongoClient(connectionString);
// var server = client.GetServer();
var databaseName = ConfigurationManager.AppSettings["MongoDBDatabaseName"];
_database = client.GetDatabase(databaseName);
}
它说,不能隐式转换类型..
这是我的整个上下文,对我来说效果很好:
public class MyContext
{
public const string COLLECTION_NAME = "CollectionName";
private static readonly IMongoClient _client;
private static readonly IMongoDatabase _database;
static MyContext()
{
var connectionString = ConfigurationManager.AppSettings["MongoDBConectionString"];
_client = new MongoClient(connectionString);
var databaseName = ConfigurationManager.AppSettings["MongoDBDatabaseName"];
_database = _client.GetDatabase(databaseName);
}
public IMongoClient Client
{
get { return _client; }
}
public IMongoCollection<TDocument> DocumentType =>
_database.GetCollection<TDocument>(COLLECTION_NAME);
}
我的代码块:
public StudentsUnitOfWork()
{
var connectionString = ConfigurationManager.AppSettings["MongoDBConectionString"];
var client = new MongoClient(connectionString);
var server = client.GetServer();
var databaseName = ConfigurationManager.AppSettings["MongoDBDatabaseName"];
_database = server.GetDatabase(databaseName);
}
VS 2015 我得到 client.GetServer() deprecated , how can I fixed it?
在我改用这个之后:
public StudentsUnitOfWork()
{
var connectionString = ConfigurationManager.AppSettings["MongoDBConectionString"];
var client = new MongoClient(connectionString);
// var server = client.GetServer();
var databaseName = ConfigurationManager.AppSettings["MongoDBDatabaseName"];
_database = client.GetDatabase(databaseName);
}
它说,不能隐式转换类型..
这是我的整个上下文,对我来说效果很好:
public class MyContext
{
public const string COLLECTION_NAME = "CollectionName";
private static readonly IMongoClient _client;
private static readonly IMongoDatabase _database;
static MyContext()
{
var connectionString = ConfigurationManager.AppSettings["MongoDBConectionString"];
_client = new MongoClient(connectionString);
var databaseName = ConfigurationManager.AppSettings["MongoDBDatabaseName"];
_database = _client.GetDatabase(databaseName);
}
public IMongoClient Client
{
get { return _client; }
}
public IMongoCollection<TDocument> DocumentType =>
_database.GetCollection<TDocument>(COLLECTION_NAME);
}