Advertisement
Guest User

Untitled

a guest
May 11th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using System.Linq;
  2. using System.Threading;
  3. using MongoDB.Bson.Serialization.Attributes;
  4. using MongoDB.Driver;
  5. using MongoDB.Driver.Builders;
  6. using MongoDB.Driver.Linq;
  7. using NUnit.Framework;
  8. using System.Collections.Generic;
  9. using System;
  10. using MongoDB.Bson;
  11. using MongoDB.Bson.Serialization;
  12. using System.Linq.Expressions;
  13.  
  14. namespace ThreadFail
  15. {
  16.     public static class Program
  17.     {
  18.         public interface IFoo
  19.         {
  20.             string Description { get; set; }
  21.         }
  22.  
  23.         [Serializable]
  24.         public class Foo : IFoo
  25.         {
  26.             public string Description { get; set; }
  27.         }
  28.  
  29.         [Serializable]
  30.         public class Bar
  31.         {
  32.             public ObjectId Id { get; set; }
  33.  
  34.             public IFoo MyFoo { get; set; }
  35.         }
  36.  
  37.         public static void Main()
  38.         {
  39.             var server = MongoServer.Create();
  40.             var database = server.GetDatabase("test");
  41.             var collection = database.GetCollection<Bar>("bars");
  42.             collection.RemoveAll();
  43.  
  44.             var bar = new Bar
  45.             {
  46.                 MyFoo = new Foo { Description = "test" }
  47.             };
  48.  
  49.             collection.Insert(bar);
  50.  
  51.             bar = collection.FindOne();            
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement