Skip to content

Commit

Permalink
Improve error message when scripting fk fails
Browse files Browse the repository at this point in the history
refs #10
  • Loading branch information
sethreno committed Nov 5, 2013
1 parent c5b0478 commit 4ec6398
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion model/ForeignKey.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Text;

namespace model {
Expand Down Expand Up @@ -35,7 +36,20 @@ public string CheckText {
get { return Check ? "CHECK" : "NOCHECK"; }
}

private void AssertArgNotNull(object arg, string argName) {
if (arg == null) {
throw new ArgumentNullException(String.Format(
"Unable to Script FK {0}. {1} must not be null.",
Name, argName));
}
}

public string ScriptCreate() {
AssertArgNotNull(Table, "Table");
AssertArgNotNull(Columns, "Columns");
AssertArgNotNull(RefTable, "RefTable");
AssertArgNotNull(RefColumns, "RefColumns");

var text = new StringBuilder();
text.AppendFormat("ALTER TABLE [{0}].[{1}] WITH {2} ADD CONSTRAINT [{3}]\r\n", Table.Owner, Table.Name, CheckText,
Name);
Expand Down

0 comments on commit 4ec6398

Please sign in to comment.