Using the MS AdventureWorks2008 SQL DB, you can see that with a SQL Client connection all PK/FK constraints are read into the schema model correctly, but using an OLE DB connection will fail to read the constraints as the SchemaOwner will always be null and the lookup will fail.
One possible workaround would be to take the TABLE_SCHEMA or PK_TABLE_SCHEMA....
public List<DatabaseConstraint> Constraints(string tableName, string schemaName)
{
//match by table name and (nullable) schema
return _constraints.Where(x =>
string.Equals(x.TableName, tableName) &&
string.Equals(x.SchemaOwner, schemaName)).ToList();
}
This is due to ConstraintKeyMap never setting SchemaKey as the CONSTRAINT_SCHEMA is never available.One possible workaround would be to take the TABLE_SCHEMA or PK_TABLE_SCHEMA....
public ConstraintKeyMap(DataTable dt, ConstraintType constraintType)
{
-----
if (!dt.Columns.Contains(SchemaKey))
{
if (!dt.Columns.Contains("TABLE_SCHEMA"))
{
if (!dt.Columns.Contains("PK_TABLE_SCHEMA"))
SchemaKey = null;
else
SchemaKey = "PK_TABLE_SCHEMA";
}
else
SchemaKey = "TABLE_SCHEMA";
}
-------------
}
Any other suggestions?