Last active
October 29, 2015 16:01
-
-
Save chrismoutray/7323b526c787b88fdd59 to your computer and use it in GitHub Desktop.
BsonDiscriminator examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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