1

Closed

Support for inheritance mappings.

description

Each EntityInfo object should have a BaseEntity property, also of type EntityInfo. It could be null when there is no base type (either no inheritance, or you're at the top of the hierarchy).
 
Currently, I have a template that creates a static GetByKey() method for each entity class.
Example output:
public static Affiliate GetByKey(Int32 key)
{
    var query =
        from ent in Context.Affiliate
        where ent.ID == key
        select ent;
        Affiliate foundEnt = query.FirstOrDefault();
    return foundEnt;
}
 
The template that generates this is:
public static <#= entInfo.Name #> GetByKey(<#= entInfo.EntityKey[0].Property.Type #> key)
{
    var query =
        from ent in Context.<#= entInfo.Name #>
        where ent.<#= entInfo.EntityKey[0].PropertyName #> == key
        select ent;
        <#= entInfo.Name #> foundEnt = query.FirstOrDefault();
    return foundEnt;
}
 
However, this does not work with inheritance:
<#= entInfo.EntityKey[0].Property.Type #>
 
You get an "ArgumentOutOfRangeException", because in table-per-type (also called table-per-subclass) mapping, the derived classes don't HAVE an EntityKey. They inherit it from the base class. This means with the current version of the SFS plugin, you can't determine the type of the EntityKey for any derived class. In fact, you can't get ANY info that's only in the base class.
Closed Jun 3, 2011 at 6:49 AM by emirtrevino
deprecated

comments