This repository was archived by the owner on Feb 22, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -153,7 +153,7 @@ private static string GetCollectionNameFromType(Type entitytype)
153153 }
154154 else
155155 {
156- if ( entitytype . Equals ( typeof ( Entity ) ) )
156+ if ( typeof ( Entity ) . IsAssignableFrom ( entitytype ) )
157157 {
158158 // No attribute found, get the basetype
159159 while ( ! entitytype . BaseType . Equals ( typeof ( Entity ) ) )
Original file line number Diff line number Diff line change @@ -338,13 +338,45 @@ public abstract class BaseA : BaseItem
338338
339339 public class SpecialA : BaseA
340340 { }
341-
341+
342342 [ TestMethod ]
343343 public void Discussion433878 ( )
344344 {
345345 var specialRepository = new MongoRepository < SpecialA > ( ) ;
346346 }
347347 #endregion
348348
349+ #region Reproduce issue: https://mongorepository.codeplex.com/discussions/572382
350+ public abstract class ClassA : Entity
351+ {
352+ public string Prop1 { get ; set ; }
353+ }
354+
355+ public class ClassB : ClassA
356+ {
357+ public string Prop2 { get ; set ; }
358+ }
359+
360+ public class ClassC : ClassA
361+ {
362+ public string Prop3 { get ; set ; }
363+ }
364+
365+ [ TestMethod ]
366+ public void Discussion572382 ( )
367+ {
368+ var repo = new MongoRepository < ClassA > ( ) {
369+ new ClassB ( ) { Prop1 = "A" , Prop2 = "B" } ,
370+ new ClassC ( ) { Prop1 = "A" , Prop3 = "C" }
371+ } ;
372+
373+ Assert . AreEqual ( 2 , repo . Count ( ) ) ;
374+
375+ Assert . AreEqual ( 2 , repo . OfType < ClassA > ( ) . Count ( ) ) ;
376+ Assert . AreEqual ( 1 , repo . OfType < ClassB > ( ) . Count ( ) ) ;
377+ Assert . AreEqual ( 1 , repo . OfType < ClassC > ( ) . Count ( ) ) ;
378+ }
379+ #endregion
380+
349381 }
350382}
You can’t perform that action at this time.
0 commit comments