I'm trying to use polymorphism for some entities, let's say I have:
[IsRoot]
Class Animal {
Id
Name
}
Class Dog: Animal {
Id
Name
HasTale
}
Class Cat: Animal {
Id
Name
DrinksMilk
}
For conventions I use:
Conventions = new DocumentConvention()
{
FindTypeTagName = type =>
{
var parents = Types.GetInheritanceTree(type);
foreach (var parent in parents)
{
if (Attributes.GetAttributes<IsRootAttribute>(parent, inheritAttributes: false).HasItems())
{
return DocumentConvention.DefaultTypeTagName(parent);
}
}
return DocumentConvention.DefaultTypeTagName(type);
}
}
A dog will be called an "animal", a cat will also be an "animal", nothing wrong with that, because there is a scenario in which I want to include both cat and dog in one index.
Now I also want to create a specific index with only "cats" to get cats which are drinking milk. What would be the easiest way to accomplish this?
In my real scenario, I got a "Planning" object, which can be eigther "AbscencePlanning", "ProjectPlanning" etc. etc. The above solution will make it possible to just get all planned items (Planning has a DateFrom, DateTo etc). So I can check everywhere if there is a duplicate planning, because of the polymorphism and the ability to query on a generic type "Project" which is available in every single assembly.
A multimap won't solve this issue, because AbsencePlanning is located in another dll (assembly) which can't access ProjectPlanning (but can access Planning) and also cannot reach the ProjectPlanning index (except when I resolve it using string, not by type). So this Polymorphism looked like a serious solution to my problem. The only thing is, I want to create a specific index for only the ProjectPlanning, but I can't find a way to only load "ProjectPlanning" objects inside my index.
Example:
Map = planning =>
from person in planning.OfType<ProjectPlanning>()
is not working. How to get the subset of Planning??