Re: Duplicate foreign keys
This is not a bug in MyGeneration. It is by design. It occurs because of the bi-directional nature of relationships.
While you only add an FK constraint on the FK column in the db, it defines a relationship between that FK column and a PK column in that or some other table. Therefore, all relationships are bi-directional. FK_Orders_Employees represents both a zero-to-many from Employees to Orders, and a many-to-one from Orders to Employees. To account for both relationships, MyGeneration's MyMeta will list that same foreign key constraint on both tables. MyGeneration also allows you to access FKs at two levels:
1) All FKs for a table. It does not matter whether the constraint is part of that table. If the table is involved on either side, the FK will be listed. In our hierarchical template, we loop through the FKs at the table level:
foreach( EntitySpaces.MetadataEngine.IForeignKey fk in table.ForeignKeys )
2) All FKs for all columns within a table. Again, it does not matter if that column has the constraint defined on it in the db. If the column is involved on either side, the FK will be listed. So, a PK column is likely to have a number of FKs listed for it, because FK constraints on columns in other tables always reference PKs somewhere. If you loop through all columns for a table and grab all FKs for each column, then a self-referencing FK like FK_Employees_Employees will show up on the FK column (ReportsTo) and the PK column (EmployeeID). That will not happen if you loop through the FKs of a single table at the table level instead.
But, if you loop through all FKs for all tables (even at the table level), and just list out FK_constraint names, you will see every one of them twice, except for self-referencing FKs. Once for the Primary table, and again for the Foreign table.
As Mike mentioned, the way to tell which side of the FK you are dealing with, is to compare the Name property of the Table whose FKs you are looping through with the PrimaryTable and ForeignTable properties of each FK.
Re: Template Posting
Let me check with Mike and Scott. We have discussed allowing users to Blog about EntitySpaces, but I think we wanted to upgrade to Community Server 2008, first. The installer crashed on us the last time we tried it, and I believe we are still waiting for a patch from CS support. That would seem to be the best approach to allowing specific users to post attachments like templates. We may have to have you zip it up and send it to support@entityspaces.net. Then we could post it for you.
David Neal Parsons
www.entityspaces.net