Skip to content

Instantly share code, notes, and snippets.

@chrismoutray
Last active October 29, 2015 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismoutray/7323b526c787b88fdd59 to your computer and use it in GitHub Desktop.
Save chrismoutray/7323b526c787b88fdd59 to your computer and use it in GitHub Desktop.
BsonDiscriminator examples
// base class
[BsonDiscriminator(RootClass = true)]
[BsonKnownTypes(typeof(Cat), typeof(Dog))]
public abstract class Animal
{
public string id { get; set; }
public string name { get; set; }
public int age { get; set; }
}
// children
[BsonDiscriminator("Cat")]
public class Cat : Animal
{
public string furballCount { get; set; }
}
[BsonDiscriminator("Dog")]
public class Dog : Animal
{
public string boneCount { get; set; }
}
// example queries
var cats = DocDb.GetQueryable<Animal>().OfType<Cat>().ToList();
var dogs = DocDb.GetQueryable<Animal>().OfType<Dog>().ToList();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment