The association names sqlmetal generates have been the source of much frustration. Sometimes the association is simply the column name with "Id" taken off the end, sometimes it generates an association name based on the foreign key constraint name.

I simply cannot figure out what steps it uses to generate these names, and a recent schema change has drastically altered the association names once again, so I'd like to get a handle on this.

I have two tables which reference each other in a sort of chain. Something like this:

class In
{
  int Id;
  EntityRef<Out> Yields;    // YieldsId => FK_Out_Source
  EntitySet<Out> In_Source; // FK_In_Source
}
class Out
{
  int Id;
  EntityRef<In> Yields;     // YieldsId => FK_In_Source
  EntitySet<In> Out_Source; // FK_Out_Source
}

These were the classes prior to the schema change, where there was an extra FK field between In and Out tables. After deleting that field, sqlmetal now generates this:

class In
{
  int Id;
  EntityRef<Out> Yields; // YieldsId => FK_Out_Source
  EntitySet<Out> Out;    // FK_In_Source
}
class Out
{
  int Id;
  EntityRef<In> In;         // YieldsId => FK_In_Source
  EntitySet<In> Out_Source; // FK_Out_Source
}

The previous classes were perfectly symmetrical as they should be, but now the generated classes are completely asymmetrical. Can anyone explain this?

有帮助吗?

解决方案

Since there seems to be no rhyme or reason to this, I created a command line tool that wraps sqlmetal and rewrites the association names. It's included in my open source Sasa utilities framework, and is called sasametal.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top