axle-h / mongo-repository

Repository pattern for the official .NET Core MongoDB driver
9 stars 7 forks source link

Polymorphism #3

Open scharada opened 4 years ago

scharada commented 4 years ago

Hi, would you please provide a sample with polymorphism ? i have tried the result is not as it should be . issue 1: when i insert a customer, the _t type is always person when it should be both "person, customer" issue 2: i also should be able to use the IRepository to find ,insert or update any customer or employee ...

it simply does not happen ... any idea why ?

here is what i did 1 - created a base class that inherits from MongoEntity. added attributes
' [BsonDiscriminator(Required = true, RootClass = true)] [BsonKnownTypes( typeof(Customer), typeof(employee), )] [CollectionName("person")] public class Person: MongoEntity { ... properties }

[BsonDiscriminator("customer", Required = true, RootClass = false)] public class Customer : Person{ ... properties }

[BsonDiscriminator("employee", Required = true, RootClass = false)] public class Employee : Person{ ... properties }'

axle-h commented 3 years ago

Missed this one... If you're still around maybe you could fork the repository and create some failing tests? Preferably integration tests?