In case you want to sync the fields up, the best way (but also the most time consuming one) is fixing them in the DB because a sync with the relational model will otherwise overwrite your fk/pk lengths again...
You have to do two things: change the target field's length and change the FK field mapped onto the field's length. In the entity model, relationships are derived from RelationshipEdge: NormalRelationshipEdge and IndirectRelationshipEdge. The former is for 1:1/1:n/m:1 relationships and the latter for m:n relationships. The method you're calling returns all relationships so you have to filter and cast, do that like this:
var entity = p.EntityModel.Vertices.FirstOrDefault(e=>e.Name=="Order");
var relationships = p.GetAllRelationshipsForEntity(entity, false);
var r = relationships.Where(x=>x.RelationshipType!=EntityRelationshipType.ManyToMany).Cast<NormalRelationshipEdge>().First();
return r.FieldRelationships;
This gives you access to the FieldRelationships
property, which is part of the NormalRelationshipEdge. These are pairs of fields (FK field and PK field) which form the relationship. These are references to the real fields, so you can alter the fk field there based on the pk field object and it should correct the length differences.
In the meta-data you can traverse all catalogs then all schemas and then all tables and for each table obtain its ForeignKeyConstraints
property. This property gives you a list of DBForeignKeyConstraint
objects, which have their fk and pk fields split in two lists (isn't legacy code lovely at times ). So the fk field at offset x in the ForeignKeyFields list of the DBForeignKeyConstraint is related to the pk field at offset x in the PrimaryKeyFields list of that same fk constraint object. So that should be straight forward to fix them up and get them in sync.
I think if you fix up both the relationships in the entity model and the FK constraints in the meta-data the errors go away already so you don't need to look up mappings and go that route too.
If you switch the sync sources in the Sync window to 'model' before running the scripts, you can make the designer track the changes too I think and export an update DDL SQL script. (In case you want to correct the target DB as well)