MongoDB C# 드라이버 2.4.2를 사용하여 일부 참조를 설정하려고 시도하지만 마지막 줄에 _db과 관련된 오류가 발생합니다. MongoDB .GetDatabase가 "필드 이니셜 라이저가 비 정적 필드, 메서드 또는 속성을 참조 할 수 없습니다."
알아낼 수 없다"A 필드 이니셜 비 정적 필드, 메소드 또는 속성 CurrentClassName._client을 참조 할 수있다."
코드 :
public class MongoDatabase<T> : ImyDB<T> where T : class, new()
{
private static string _connectionString = ConfigurationManager.ConnectionStrings["db"].ConnectionString;
private string _dbName;
private MongoClient _client = new MongoClient(_connectionString);
private IMongoDatabase _db = _client.GetDatabase(_dbName);