Specifies that the fields defined on the type are stored along in the same table with the fields of the base type.
Mapping the type with <SharedInheritance> element defines the extent provider of the type. The extent provider uses the table of the base type to store additional fields of the type in the underlying relational database system. This table is specified by the first joined or root inheritance in the path of the base types of the type up to the root.
The additional fields defined in the table are only used for the rows
that store instances of the type or its derived types.
The fields contain
NULL
values for rows that store instances of types
that do not derive from type.
| Id fields | fields of the T0 | fields of T |
|---|---|---|
| #1 | field values of object #1 |
NULL
|
| #2 | field values of object #2 |
NULL
|
| #3 | field values object #3 | |
#1 and #2 are instances of T0
and object #3 is an instance of T)
Using shared inheritance should be considered when the application uses the extent of the base type frequently and the type does not define a significant number of additional fields. When Genome queries the extent of the base type by using shared inheritance, no further joining has to be performed.
The fields of Supplier are stored in the BusinessContact table.
BusinessContact.cs
public abstract class BusinessContact : Persistent {
public abstract int Id { get; set }
public abstract string CompanyName { get; set }
...
}
public abstract class Supplier : BusinessContact {
public abstract string HomePage { get; set; }
...
}
NorthwindSchema.xml
<Mapping xmlns="urn:TechTalk:TT.OODAL.XmlMapping">
...
<Type name="BusinessContact">
<RootInheritance />
...
<Member name="Id" PersistentField="Id" />
<Member name="CompanyName" PersistentField="Name" />
</Type>
<Type name="Supplier">
<SharedInheritance />
<!-- the "BusinessContact" table will be used to store the homepage -->
...
<Member name="HomePage" PersistentField="HomePage" />
</Type>
</Mapping>
Using the schema defined above, the OQL query
extentof(BusinessContact)[CompanyName=="Exotic Liquids"]
is translated to
SELECT * FROM BusinessContact WHERE Name='Exotic Liquids'
Type: TechTalk.Genome.Mapping.SharedInheritanceXmlData
Assembly: TechTalk.Genome.dll
Version: 4.2.4
Editions: Professional, Evaluation, Express
Database Platforms: Microsoft SQL Server 2000, Microsoft SQL Server 2005, Oracle 9i Release 2, Oracle 10g Release 2
Type Extent Providers | <RootInheritance> Element | <JoinedInheritance> Element