private EntityMetaData DetermineJoinTable <ONE, MANY>() where ONE : class where MANY : class { try { EntityMetaData joinTableMD = entityMetaData.GetMeta4JoinEntity( entityMetaData.GetMeta4Entity <ONE>(), entityMetaData.GetMeta4Entity <MANY>()); if (joinTableMD == null) { throw new ArgumentException("Entity type unknown in repository."); } return(joinTableMD); } catch (Exception e) { throw e; } }
// For Insert: For the potential new situation: Outbound references: If fkKey is nullable AND contains nullvalues then allow else see function "NumberOfRecordsMatchesMultiplicity" // Inbound references: no test needed. // For Delete: For the potential new situation: Outbound references: First check for Cascade deletes, if so Cascade the deletion else always allow // Inbound references: See functon "NumberOfRecordsMatchesMultiplicity4Delete" // For Update: For the potential new situation: Outbound references: Same as Insert. // Inbound references: Always allow private async Task <Boolean> CheckInboundReferences(dynamic record) { EntityMetaData recordMD = entityMetaData.GetMeta4Entity(record); if (recordMD == null) { throw new ArgumentException("Entity type unknown in repository."); } foreach (var inRefEntity in recordMD.inRefs) { foreach (var foreignKey in inRefEntity.outRefs) // foreignKey inRef---->----references---->record (= record to delete) { if (foreignKey.referredEntity != recordMD) { break; //only Inrefs to "me" } { // now we have got all the inbound references. if (!CheckMetaDataArguments(foreignKey)) { return(false); } object[] KeyValues = property.GetPropertyValues(record, foreignKey.foreignKeyProjectionProperties); if (NullAllowedAndPresent(foreignKey, KeyValues)) { break; } int Referrers = await CountOccurencesOfEntityAsync( inRefEntity.entity, foreignKey.foreignKeyProperties, KeyValues); if (Referrers == 0) { break; // Nobody is referring to current record, so no need to check! } int recordCnt = await CountOccurencesOfEntityAsync( foreignKey.referredEntity.entity, foreignKey.foreignKeyProjectionProperties, KeyValues); if (!NumberOfRecordsMatchesMultiplicity4Delete(recordCnt, foreignKey.multiplicity)) { return(false); } break; } } } return(true); }