Guest User

Untitled

a guest
Mar 13th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. public class DummyClass
  2. {
  3. [BsonId]
  4. public int Id { set; get; }
  5.  
  6. [BsonElement("first")]
  7. public string First { set { _name = value; } }
  8.  
  9. [BsonConstructor]
  10. public DummyClass()
  11. {
  12. Id = 2;
  13. First = "1";
  14. }
  15. }
  16.  
  17. _dbClient = new MongoClient();
  18. _database = _dbClient.GetDatabase("testDB");
  19. _collection = _database.GetCollection<BsonDocument>("Collection");
  20.  
  21. var doc = BsonDocument.Create(dummy);
  22. _collection.InsertOneAsync(doc);
  23.  
  24. System.ArgumentException : .NET type DummyClass cannot be mapped to BsonType.Document.
  25. Parameter name: value
  26.  
  27. {
  28. {"Id", "2"},
  29. {"First", "1"},
  30. }
  31.  
  32. BsonClassMap.RegisterClassMap<DummyClass>();
  33.  
  34. _collection = _database.GetCollection<DummyClass>("Collection");
  35. await _collection.InsertOneAsync(doc);
  36.  
  37. _collection.InsertOneAsync(doc.ToBsonDocument())
Add Comment
Please, Sign In to add comment