Skip to content

Commit 8f7cde7

Browse files
committed
changed builder to assume that if the discriminator did not show up then the class is the base class.
1 parent 62fc6e4 commit 8f7cde7

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

examples/Simple/Main.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ public static void Main(string[] args)
8181
collection.Save(circle);
8282
collection.Save(sub);
8383

84+
var superclass = (from item in db.GetCollection<MyClass>("MyClass").Linq()
85+
where item.Corners > 1
86+
select item.Corners).ToList();
87+
88+
var subclass = (from item in db.GetCollection<SubClass>("MyClass").Linq()
89+
where item.Ratio > 1
90+
select item.Corners).ToList();
91+
8492
Console.WriteLine("Count by LINQ on typed collection: {0}", collection.Linq().Count(x => x.Corners > 1));
8593
Console.WriteLine("Count by LINQ on typed collection2: {0}", db.GetCollection<SubClass>().Linq().Count(x => x.Corners > 1));
8694
//Console.WriteLine("Count by LINQ on typed collection3: {0}", db.GetCollection<SubClass>().Count(new { Corners = Op.GreaterThan(1) }));

source/MongoDB/Serialization/Builders/PolymorphicClassMapBuilder.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ public void AddProperty(string name, object value)
3838
public object BuildObject()
3939
{
4040
if (_concreteEntityBuilder == null)
41-
throw new Exception("Discriminator did not show up.");
41+
{
42+
//we'll assume that this is the root class in the hierarchy.
43+
_concreteEntityBuilder = new ConcreteClassMapBuilder(_classMap);
44+
}
4245

4346
return _concreteEntityBuilder.BuildObject();
4447
}

0 commit comments

Comments
 (0)