title: Creating table relationships in SQL Server via C#
body: <p>I want to create relationships in my SQL Server database using C#.</p>
  
  <p>I have this code:</p>
  
  <pre><code>   foreach (ForeignKey fk in table.ForeignKeys)
                  {
                      if (!table.ForeignKeys.Contains("ProductMaterial"))
                  }
  
                  table.ForeignKeys.Add(
                       new ForeignKey(
                          new Table(database, 
                                    "ProductMaterial"), 
                                    "ProductMaterial" ));
                  DataRelation relation = new DataRelation(
                          "ProductMaterial", new DataColumn(), )
  </code></pre>
  
  <p>"table" is from a Tables collection in the database, and the database comes from a databases collection in the server instance. I have the condition reversal because I want to add a relationship obviously where one does not exist so I am looking for the absence of an FK.</p>
  
  <p>However, I also have the DataRelation line. Can I just add an FK and that'll be the relationship? Or should I add both an FK and a datarelation object?</p>
  
  <p>Thanks</p>