It’s all in the links you posted. The class InheritanceMappingAttribute
maps an inheritance hierarchy into a LINQ
to SQL
app.
The builder InheritanceMappingAttribute()
initializes a new class instance InheritanceMappingAttribute
.
Estates
Code
: Obtains or defines the value of the code discriminator in a mapped heritage hierarchy.
IsDefault
: Obtains or defines whether an object of this type at the instantiation when the value of the discriminator does not match a specified value.
Type
: Obtains or defines the class type in the hierarchy.
TypeId
: When implemented in a derivative class, you get a unique identifier for this Attribute
.(inherited from Attribute.)
When mapping inheritance hierarchies, note the following:
All classes in a hierarchy should be mapped to a single table.
The table for an inheritance hierarchy must be declared in the mapped type that is at the top of the hierarchy. You cannot specify table mapping attributes in a class that is derived from the upper class.
You can use an interface in a hierarchy, but LINQ is not mapped.
You can ignore a class in the hierarchy when mapping classes, but you can only refer to mapped classes.
For correct materialization, code values of the discriminator must be unique and correspond to the values in the database. A line with a code value of the discriminator matches exactly (even by upper and lower case) creates an instance of the class using IsDefault
defined as true
.
On the property IsDiscriminator
, it obtains or defines whether a column contains a discriminator value for a LINQ
to SQL
inheritance hierarchy. The default is false
.
When you use true
, this property identifies the class member that contains the value of the discriminator for an inheritance hierarchy.
Example of documentation:
[Column(Storage="_Title", DbType="NVarChar(30)",IsDiscriminator=true)]
public string Title
{
get
{
return this._Title;
}
set
{
if ((this._Title != value))
{
this.OnTitleChanging(value);
this.SendPropertyChanging();
this._Title = value;
this.SendPropertyChanged("Title");
this.OnTitleChanged();
}
}
}
About the Shape class: see these two links in the documentation: Class Shape and Shapetype.
Taking advantage of the topic, I would like to ask another question. Will the data contained in the three classes be saved in the same table in the database? What if in the database they are in separate tables? For example, say I have, the following hierarchy
Veiculo
(Father),Carro
(Derivative),Moto
(Derived) and that in db they are represented in separate tables, ie a table p/ each class, simulating inheritance through relationship. How it would look?– Matheus Saraiva
Cont.... . I mean, what would the code c# LINQ look like, and not the structure of the tables. The tables I already have ready.
– Matheus Saraiva