I'm implementing a domain tree structure using entity framework + mvc. I use JSTree to present the org structure.
Note that in that model scheme i use the TypeID property both as a condition of my inheritance and as a property for DomainEntity.
This of corse throw the following error:
Error 3 Error 3032: Problem in mapping fragments starting at line 139:Condition member 'DomainEntities.EntityTypeID' with a condition other than 'IsNull=False' is mapped. Either remove the condition on DomainEntities.EntityTypeID or remove it from the mapping. C:\Code\CamelotShiftManagement\CamelotShiftManagement\Models\CamelotDB.edmx 140 15 CamelotShiftManagement
lets say i will not use TypeID as a property and keep it as a condition for the inheritance association that will result in the following when i'll try to populate a tree of my domain entities:
foreach (var entity in entities)
{
JsTreeModel tree = new JsTreeModel()
{
attr = new JsTreeAttribute()
{
id = entity.EntityID.ToString(),
},
data = entity.EntityName
};
if (entity is OrganizatioanlUnit)
{
tree.attr.type = eNodeType.OrganizationalUnit;
}
if (entity is Calendar)
{
tree.attr.type = eNodeType.Calendar;
}
PopulateTree(entity, tree);
io_Node.children.Add(tree);
}
this code is not maintainable because when a new entity will be introduced i will have to change this code, if i could only access a property that will tell me the type of entity i'm dealing with .. :) .
Here is the dilemma: If i use inheritances and TypeID as a condition for each inheritance i can not access it as a property of DomainEntity, that will require me to use switch-case against typof(entity) to determine what type i should send to my JSTree plugin because he expects a type identification for each node in his JSON, if i will not use inheritance i will loose the polymorphic capabilities.
It is not only polymorphism i am after.. there will be other methods and properties relevant only for the inherited entities and i can see some injections points in the future...