public static DbColumn ForeignKey(DbTable table, bool allowNull = false, string foreignKeyName = null) { if (table == null) { throw new ArgumentNullException("table"); } foreach (var column in table.Columns) { if (column.IsPrimaryKey) { return(new DbColumn(DbColumnType.Integer, foreignKeyName ?? NameProvider.GetDbForeignKeyName(table.ClassName), allowNull) { DbForeignKey = new DbForeignKey(table.Name, column.Name) }); } } throw new Exception(@"No Primary Key column."); }