这就是我到目前为止关于我的 IRepository for MongoDB 的内容,我想知道我是否在正确的路线上?
public abstract class Repository<TEntity> : IRepository<TEntity> {
private const string _connection = "mongodb://localhost:27017/?safe=true";
private MongoDatabase _db;
protected abstract string _collection{get;}
public Repository() {
this._db = MongoServer.Create(_connection).GetDatabase("Photos");
}
public IQueryable<TEntity> FindAll() {
return this._db.GetCollection<TEntity>(_collection).FindAll().AsQueryable();
}
}
这样我就可以创建从这里继承的 PhotoRepository 类并提供所需的 _collection 名称。
我只想确保在正确的位置以正确的方式打开与数据库的连接。