I am currently using Breeze 1.5.3.
I have defined the metadata for my model so that there is a unidirectional one-to-many relationship between two entities Column
-> ColumnStatistic
.
When I inspect the JSON returned by my service I see a ColumnStatistics
collection for each Column
, but this collection is empty when I inspect the resulting entities.
I'm using EF6 to provide the primary and foreign key information. The relevant statements in my OnModelCreating method are the following ones.
modelBuilder.Entity<Column>().HasKey(c => new { c.Owner, c.TableName, c.ColumnName});
modelBuilder.Entity<ColumnStatistic>().HasKey(s=> new { s.Owner, s.TableName, s.ColumnName, s.StatisticName });
modelBuilder.Entity<Column>().HasMany(c => c.ColumnStatistics).WithRequired().HasForeignKey(s => new { s.Owner, s.TableName, s.ColumnName });
I've created a plunker for this example. The example is a little more complicated than it needs to be since it contains metadata for entities outside the scope of this writeup, but I clearly see the Column_ColumnStatistics
relationship in my metadata along with the associated foreign key constraint.
"association": [{
"name": "Column_ColumnStatistics",
"end": [{
"role": "Column_ColumnStatistics_Source",
"type": "Edm.Self.Column",
"multiplicity": "1",
"onDelete": {"action": "Cascade"}
},
{
"role": "Column_ColumnStatistics_Target",
"type": "Edm.Self.ColumnStatistic",
"multiplicity": "*"
}],
"referentialConstraint": {
"principal": {
"role": "Column_ColumnStatistics_Source",
"propertyRef": [{"name": "Owner"},
{"name": "TableName"},
{"name": "ColumnName"}]
},
"dependent": {
"role": "Column_ColumnStatistics_Target",
"propertyRef": [{"name": "Owner"},
{"name": "TableName"},
{"name": "ColumnName"}]
}
}
}
All foreign key fields appear in the instances of ColumnStatistic
returned by my service. A typical example of this data is the following.
{
"$id": "1",
"$type": "Archive.DtoModels.OracleMetadata.Column, Archive",
"Owner": "FUSION",
"TableName": "SGP_STUDENT",
"ColumnName": "CONSOLIDATED_SUBGROUP_CURR",
"DataType": "VARCHAR2",
"ColumnStatistics": [{
"$id": "2",
"$type": "Archive.DtoModels.OracleMetadata.ColumnStatistic, Archive",
"Owner": "FUSION",
"TableName": "SGP_STUDENT",
"ColumnName": "CONSOLIDATED_SUBGROUP_CURR",
"StatisticName": "HasNull",
"StatisticValue": 0},...]
}
Also, when I inspect the ColumnStatistics
property of the Column
entity type in my metadataStore
I see that invForeignKeyNames
is correctly defined as the three value composite key that I specify in the metadata. By design inverse
is undefined because I intend this to be a unidirectional navigation property from the one side to the many side only.
Based on my reading of the Breeze release notes, the definedness of invForeignKeyNames
should be sufficient to guarantee 1 to n navigability in versions >= 1.3.5. Since invForeignKeyNames
is defined in my case, the situation appears to be different than that outlined in the post closest to mine that I managed to uncover on this site. Without having yet delved into the breeze source code, I am wondering if the composite keys in my example are part of the problem?