I require an understanding on the Map Method API located in the Entity Framework Namespace.
The Method signature is:-
public EntityTypeConfiguration
Action
where TDerived : class, TEntityType)
My question is...
Why does the where constraint need to have the TDerived generic placeholder telling it that it must derive from a class (reference type) AND to be of type TEntityType?
I commented out the where constraint and it still seemed to work fine?
Regards
VulpesPosted Apr 30, 2013, 3:57 PM
T, here, is of course EntityMappingConfiguration
Delegate parameters aren't confined to Action
Guest UserPosted Apr 30, 2013, 12:46 PM
As we know the Action delegate takes a single input parameter and does NOT return a value.
Ive only ever seen an Action delegate in use with methods so I assume that because a class itself doesnt directly return a value this is able to work?
VulpesPosted Apr 30, 2013, 11:07 AM
http://msdn.microsoft.com/en-us/library/gg679466(v=vs.103).aspx
and it does make it clear that TDerived must be a derived entity type. It's not possible for it to be a struct which always derive directly from System.ValueType so it must therefore be a class.
The purpose of the 'where' constraint is to catch at compile time any attempt to use an unsuitable type which is probably an indication that the code within the method will assume that TDerived is a class which derives from TEntityType.
If you comment out the constraint but still use a suitable type, then the method will probably still work OK but it probably won't work OK if you pass it an unsuitable type.