sqlmetal doesn't like your tables. The relevant code is:
var otherType = database.Tables.Single(t => t.Type.Name == association.Type).Type;
var otherAssociation = otherType.Associations.Single(a => a.Type == table.Type.Name && a.ThisKey == association.OtherKey);
var otherColumn = otherType.Columns.Single(c => c.Member == association.OtherKey);
if (association.CardinalitySpecified && association.Cardinality == Cardinality.Many && association.IsForeignKey)
{
error = true;
Log.WriteErrorLine("Error DBML1059: The IsForeignKey attribute of the Association element '{0}' of the Type element '{1}' cannnot be '{2}' when the Cardinality attribute is '{3}'.",
association.Name, table.Type.Name, association.IsForeignKey, association.Cardinality);
}
So one of those .Single() calls is failing because either 0 items are present or more than one item is present, thus preventing sqlmetal from further validating your schema (and possibly generating other errors).
To narrow down which line is failing, run your command with MONO_OPTIONS set:
$ MONO_OPTIONS=--debug sqlmetal ...
That should provide line numbers in the exception message.
The intent of the above block of code is to ensure that the table cross-references are "sane" -- that for an association:
1. There is only one matching Type for the association.
2. The matched type (1) has an association to the "current" association, i.e. it's bidirectional
3. The referenced column in the matching type (1) actually exists.
In a well normalized table schema, these should all be valid, but it's fairly easy to break this...
- Jon