private ConstraintException EnforceCheckConstraints(object refItem)
{
var refTables = _databaseDatabase.GetMappings(_typeInfo.Type);
foreach (var localDbReposetory in refTables)
{
var fkPropForTypeX =
_typeInfo.Propertys.FirstOrDefault(
s =>
s.Value.ForginKeyDeclarationAttribute != null &&
s.Value.ForginKeyDeclarationAttribute.Attribute.ForeignTable ==
localDbReposetory.TypeInfo.TableName)
.Value;
if (fkPropForTypeX == null)
{
continue;
}
var fkValueForTableX = fkPropForTypeX.Getter.Invoke(refItem);
if (fkValueForTableX != null && !localDbReposetory.ContainsId(fkValueForTableX))
{
return(new ForginKeyConstraintException(
"ForginKey",
_typeInfo.TableName,
localDbReposetory.TypeInfo.TableName,
fkValueForTableX,
_typeInfo.PrimaryKeyProperty.PropertyName,
fkPropForTypeX.PropertyName));
}
}
return(null);
}