BookStoreContext.cs 815 B

123456789101112131415161718192021222324252627
  1. using Microsoft.EntityFrameworkCore;
  2. using MongoDB.Driver;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Configuration;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace BookStore
  10. {
  11. public class BookStoreContext : DbContext
  12. {
  13. private IMongoDatabase _db { get; set; }
  14. private MongoClient _mongoClient { get; set; }
  15. public BookStoreContext()
  16. {
  17. _mongoClient = new MongoClient(ConfigurationManager.ConnectionStrings["BookStore"].ConnectionString);
  18. _db = _mongoClient.GetDatabase(ConfigurationManager.ConnectionStrings["BookStore"].Name);
  19. }
  20. public IMongoCollection<T> GetCollection<T>(string nameCollection)
  21. {
  22. return _db.GetCollection<T>(nameCollection);
  23. }
  24. }
  25. }