This question is locked. New answers and comments are not allowed.
Hello,
I'm trying to define the model like this:
I'm making the mapping like this:
Model compiles without any errors, the database structure generated by OpenAccessContext looks good and I can do such operation:
Both 'root' and 'home' are correctly writed to the database, but nothing is saved to the join table, so there is no association created... :(
best regards
pk
I'm trying to define the model like this:
public
abstract
class
Element
{
public
int
Id {
get
;
private
set
; }
public
string
Name {
get
;
set
; }
public
IList<Catalog> Catalogs {
get
;
private
set
; }
public
Element()
{
Catalogs =
new
List<Catalog>();
}
}
public
class
Catalog: Element
{
public
bool
CanHoldCatalogs {
get
;
set
; }
public
IList<Element> Entries {
get
;
private
set
; }
public
Catalog()
{
Entries =
new
List<Element>();
}
}
//and of course, other classes inherited from Element
I'm making the mapping like this:
MappingConfiguration<Element> elementMap =
new
MappingConfiguration<Element>();
elementMap.MapType().ToTable(
"Elements"
);
elementMap.HasDiscriminator().ToColumn(
"class"
).HasColumnType(
"char"
).HasPrecision(10);
elementMap.HasProperty(p => p.Id).IsIdentity(KeyGenerator.Autoinc);
MappingConfiguration<Catalog> catalogMap =
new
MappingConfiguration<Catalog>();
catalogMap.MapType().Inheritance(InheritanceStrategy.Vertical).ToTable(
"Catalogs"
);
catalogMap.HasDiscriminatorValue(
"catalog"
);
catalogMap.HasAssociation(a => a.Entries).WithOpposite(o => o.Catalogs)
.MapJoinTable(
"CatalogEntries"
, (c,e) =>
new
{CatalogID=c.Id,ElementId=c.Id});
Model compiles without any errors, the database structure generated by OpenAccessContext looks good and I can do such operation:
var root =
new
Catalog {Name =
"root"
};
var home =
new
Catalog {Name =
"home"
};
root.Entries.Add(home);
context.Add(root);
context.SaveChanges();
Both 'root' and 'home' are correctly writed to the database, but nothing is saved to the join table, so there is no association created... :(
best regards
pk