Permalink
Browse files

[Contrib][T4] Add support at ForeignKey UpdateRule and DeleteRule

  • Loading branch information...
1 parent 618660c commit 4fb41b328c71d344292c558e87d5af335fd65248 @spaccabit committed Dec 3, 2012
@@ -120,7 +120,7 @@ foreach(ForeignKey fkey in FKeyList)
if(!string.IsNullOrEmpty(fkey.Name))
{
#>ForeignKey("<#=fkey.Name#>")<#
- } #>.FromTable("<#=tbl.Name#>").InSchema("<#=fkey.ForeignTableSchema#>").ForeignColumns(<#=Join(fkey.ForeignColumns)#>).ToTable("<#=fkey.PrimaryTable#>").InSchema("<#=fkey.PrimaryTableSchema#>").PrimaryColumns(<#=Join(fkey.PrimaryColumns)#>);
+ } #>.FromTable("<#=tbl.Name#>").InSchema("<#=fkey.ForeignTableSchema#>").ForeignColumns(<#=Join(fkey.ForeignColumns)#>).ToTable("<#=fkey.PrimaryTable#>").InSchema("<#=fkey.PrimaryTableSchema#>").PrimaryColumns(<#=Join(fkey.PrimaryColumns)#>)<#=generator.GetUpdateDeleteRule(fkey)#>;
<#
}
}
@@ -318,5 +318,15 @@ public string GetMigrationTypeFunctionForType(Column col)
return sysType;
}
+
+ public string GetUpdateDeleteRule(ForeignKey fk)
+ {
+ var sb = new System.Text.StringBuilder();
+ if (fk.UpdateRule!=System.Data.Rule.None)
+ sb.AppendFormat(".OnUpdate(System.Data.Rule.{0})", fk.UpdateRule);
+ if (fk.DeleteRule != System.Data.Rule.None)
+ sb.AppendFormat(".OnDelete(System.Data.Rule.{0})", fk.DeleteRule);
+ return sb.ToString();
+ }
}
}
@@ -23,5 +23,8 @@ public ForeignKey()
public ICollection<string> ForeignColumns { get; set; }
public string PrimaryClass { get; set; }
+
+ public System.Data.Rule UpdateRule { get; set; }
+ public System.Data.Rule DeleteRule { get; set; }
}
}

0 comments on commit 4fb41b3

Please sign in to comment.