Hi,
I want to create relationships in my SQL Server database using C#.
I have this 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(), )
"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.
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?
Thanks