*** MY RE-WRITE APPROACH WILL NOT WORK ***
Mea Culpa for misleading anyone. I thought we didn't support injected types for lack of time. Not so. We tried. The problem lies with the Entity Framework.
EF will not let us inject an unmapped class in the middle of a mapped hierarchy.
The CSDL inheritance hierarchy is "Apple -> Fruit". The CLR class hierarchy (after my proposed surgery) is "Apple -> RoundFruit -> Fruit". Entity Framework examines the CLR class hierarchy, doesn't recognize "RoundFruit", screams "mismatch", and refuses to materialize the Apple.
Note that EF does not consider super classes of Fruit (e.g., Entity, or YourBaseType). EF cares only about the mapped portion of the hierarchy. That's why we can support an injected base type ... but not injected intermediate types.
How about creating a fictive RoundFruit class in the EDMX? One without any mapped properties. Sorry but EF refuses to validate the model. We don't think this is just a designer problem.
We understand that the EF team is aware of the issue and may support "empty" abstract classes in future. Then you could insert an empty RoundFruit class in your CSDL and extend the generated partial class in code.
Until that happy day, you'll have to use ugly workarounds. I have some in mind ... but will keep them to myself until someone needs them.
Hint: think "extension methods" , implemented in the same assembly as your custom base class, leveraging an "internal" method of your base class to enable the extension method to access non-public members.
@pk55 may be able to escape the problem because it seems he does not need intermediate base types. It appears that all of his custom, pure-code base types are positioned outside the mapped hierarchy.
Continuing my example, it looks like he has entities such as:
Apple -> Fruit -> PlantBase -> GeneralBase -> Entity
Orange -> Fruit -> PlantBase -> GeneralBase -> Entity
BeefSteak -> Ruminant -> MeatBase -> GeneralBase -> Entity
ChickenSteak -> Poultry -> MeatBase -> GeneralBase -> Entity
Apple, Orange, BeefSteak, ChickenSteak, Fruit, Ruminant, Poultry ... these are all mapped entities. PlantBase and MeatBase are custom, abstract, pure code classes that descend from GeneralBase which derives from our Entity. None of the custom base classes intrude into the mapped hierarchy. Entity Framework will be fine.
@pk55 will be still have to either surgically alter the generated classes or customize our code generation ... which approaches I described above.
--
Regarding the "." kludge ... yes it is. We considered examining the project to see if the named class exists. This seemed vulnerable to timing problems that would lead to tedious support calls. We think the "." convention removes all ambiguity. Reasonable minds will differ.
---
Yes, it would be nice to be able to annotate through the designer. Oh well. You will have access to attributes (such as the documentation attributes) during DevForce code generation interception so you could read those to give your logic the inheritance direction it needs; that same generation could also strip those directions from the generated XML documentation if you preferred. It's all up to you.
I'd be inclined toward a different approach. I'd probably leverage some class naming convention that indicated the appropriate base class to use and supplement that with a separate configuration file to override the convention as needed.
You certainly want to write some tests that confirm you've generated these special entity types as expected.
Best of luck!
Edited by WardBell - 20-Apr-2010 at 12:13pm