using System; using System.Collections.Generic; using System.Linq; using System.Text; using MongoDB.Bson; using MongoDB.Driver; using MongoDB.Driver.Linq; namespace TestCSharp526 { public interface IC { int X { get; set; } } public class C : IC { public int Id { get; set; } public int X { get; set; } } public static class Program { public static void Main(string[] _args) { try { var server = MongoServer.Create("mongodb://localhost/?safe=true"); var database = server.GetDatabase("test"); var collection = database.GetCollection("csharp526"); if (collection.Count() == 0) { collection.Insert(new C { Id = 1, X = 1 }); } var ic = collection.AsQueryable().FirstOrDefault(i => i.X == 1); Console.WriteLine(ic.ToJson()); } catch (Exception ex) { Console.WriteLine("Unhandled exception:"); Console.WriteLine(ex); } Console.WriteLine("Press Enter to continue"); Console.ReadLine(); } } }