本文整理汇总了C#中System.Data.ForeignKeyConstraint类的典型用法代码示例。如果您正苦于以下问题:C# ForeignKeyConstraint类的具体用法?C# ForeignKeyConstraint怎么用?C# ForeignKeyConstraint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ForeignKeyConstraint类属于System.Data命名空间,在下文中一共展示了ForeignKeyConstraint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: run
//Activate This Construntor to log All To Standard output
//public TestClass():base(true){}
//Activate this constructor to log Failures to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, false){}
//Activate this constructor to log All to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, true){}
//BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
public void run()
{
Exception exp = null;
DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
ForeignKeyConstraint fc = null;
fc = new ForeignKeyConstraint("myForeignKey",dtParent.Columns[0],dtChild.Columns[0]);
try
{
BeginCase("Ctor");
Compare(fc == null ,false );
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
try
{
BeginCase("Ctor - name");
Compare(fc.ConstraintName ,"myForeignKey" );
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
}
示例2: run
//Activate This Construntor to log All To Standard output
//public TestClass():base(true){}
//Activate this constructor to log Failures to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, false){}
//Activate this constructor to log All to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, true){}
//BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
public void run()
{
Exception exp = null;
DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
ForeignKeyConstraint fc = null;
fc = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);
try
{
BeginCase("ToString - default");
Compare(fc.ToString(), string.Empty );
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
fc = new ForeignKeyConstraint("myConstraint",dtParent.Columns[0],dtChild.Columns[0]);
try
{
BeginCase("Tostring - Constraint name");
Compare(fc.ToString(), "myConstraint");
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
}
示例3: run
//Activate This Construntor to log All To Standard output
//public TestClass():base(true){}
//Activate this constructor to log Failures to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, false){}
//Activate this constructor to log All to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, true){}
//BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
public void run()
{
Exception exp = null;
DataSet ds = new DataSet();
DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
ds.Tables.Add(dtParent);
ds.Tables.Add(dtChild);
dtParent.PrimaryKey = new DataColumn[] {dtParent.Columns[0]};
ds.EnforceConstraints = true;
ForeignKeyConstraint fc1,fc2;
fc1 = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);
fc2 = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[1]);
try
{
BeginCase("different columnn");
Compare(fc1.Equals(fc2),false);
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
//Two System.Data.ForeignKeyConstraint are equal if they constrain the same columns.
try
{
BeginCase("same column");
fc2 = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);
Compare(fc1.Equals(fc2),true);
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
}
示例4: run
//Activate This Construntor to log All To Standard output
//public TestClass():base(true){}
//Activate this constructor to log Failures to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, false){}
//Activate this constructor to log All to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, true){}
//BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
public void run()
{
Exception exp = null;
DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
DataTable dtChild = GHTUtils.DataProvider.CreateParentDataTable();
ForeignKeyConstraint fc = null;
fc = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);
PropertyCollection pc = fc.ExtendedProperties ;
try
{
base.BeginCase("Checking ExtendedProperties default ");
base.Compare(fc != null,true);
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
try
{
base.BeginCase("Checking ExtendedProperties count ");
base.Compare(pc.Count ,0);
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
}
示例5: run
//Activate This Construntor to log All To Standard output
//public TestClass():base(true){}
//Activate this constructor to log Failures to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, false){}
//Activate this constructor to log All to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, true){}
//BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
public void run()
{
Exception exp = null;
//int RowCount;
DataSet ds = new DataSet();
DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
ds.Tables.Add(dtParent);
ds.Tables.Add(dtChild);
ForeignKeyConstraint fc = null;
fc = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);
try
{
BeginCase("Columns");
Compare(fc.Columns[0] ,dtChild.Columns[0] );
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
try
{
BeginCase("Columns count");
Compare(fc.Columns.Length ,1 );
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
}
示例6: run
//Activate This Construntor to log All To Standard output
//public TestClass():base(true){}
//Activate this constructor to log Failures to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, false){}
//Activate this constructor to log All to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, true){}
//BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
public void run()
{
Exception exp = null;
DataSet ds = new DataSet();
DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
ds.Tables.Add(dtParent);
ds.Tables.Add(dtChild);
ForeignKeyConstraint fc = null;
fc = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);
try
{
BeginCase("default ");
Compare(fc.ConstraintName ,string.Empty );
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
fc.ConstraintName = "myConstraint";
try
{
BeginCase("set/get ");
Compare(fc.ConstraintName ,"myConstraint" );
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
}
示例7: AddForeignKeyConstraint
public static void AddForeignKeyConstraint( DataSet ds )
{
DataColumn parent = ds.Tables["Categories"].Columns["CategoryID"] ;
DataColumn child = ds.Tables["Products"].Columns["CategoryID"] ;
ForeignKeyConstraint fk = new ForeignKeyConstraint ( "FK_Product_CategoryID" , parent , child ) ;
fk.UpdateRule = Rule.Cascade ;
fk.DeleteRule = Rule.SetNull ;
// Create the constraint
// If this fails, you have a row in the products table with no associated category
ds.Tables["Products"].Constraints.Add ( fk ) ;
}
示例8: foreach
internal DesignRelation this[ForeignKeyConstraint constraint]
{
get
{
if (constraint != null)
{
foreach (DesignRelation relation in this)
{
if (relation.ForeignKeyConstraint == constraint)
{
return relation;
}
}
}
return null;
}
}
示例9: Main
static void Main(string[] args)
{
DataSet shopDB = new DataSet("ShopDB");
DataTable orders = new DataTable("Orders");
DataTable customers = new DataTable("Customers");
string conStr = @"Data Source=(localdb)\MSSQLLocalDB; Initial Catalog=ShopDB; Integrated Security=True;"; // создание строки подключения
using (SqlConnection connection = new SqlConnection(conStr))
{
connection.Open();
SqlCommand customersCmd = new SqlCommand("SELECT CustomerNo, LName, FName, Address1, Phone FROM Customers", connection);
SqlCommand ordersCmd = new SqlCommand("SELECT OrderID, CustomerNo, OrderDate FROM Orders", connection);
SqlDataReader ordersReader = ordersCmd.ExecuteReader(); // получение DataReader для таблицы OrderDetails
// метод LoadWithSchema позволяет на основе объекта DataReader создать объект DataTable
//с ограничениями для столбцов как в базе данных и заполнить эту таблицу данными
orders.LoadWithSchema(ordersReader);
ordersReader.Close();
SqlDataReader customersReader = customersCmd.ExecuteReader();
customers.LoadWithSchema(customersReader);
customersReader.Close();
}
customers.PrimaryKey = new DataColumn[] { customers.Columns[0] };
shopDB.Tables.AddRange(new DataTable[] { customers, orders });
// создание ограничения ForeignKeyConstraint для таблицы OrderDetails
var FK_CustomersOrders = new ForeignKeyConstraint(customers.Columns["CustomerNo"], orders.Columns["CustomerNo"]);
orders.Constraints.Add(FK_CustomersOrders);
Console.ReadKey();
}
示例10: Columns
[Test] public void Columns()
{
//int RowCount;
DataSet ds = new DataSet();
DataTable dtParent = DataProvider.CreateParentDataTable();
DataTable dtChild = DataProvider.CreateChildDataTable();
ds.Tables.Add(dtParent);
ds.Tables.Add(dtChild);
ForeignKeyConstraint fc = null;
fc = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);
// Columns
Assert.AreEqual(dtChild.Columns[0] , fc.Columns[0] , "FKC1");
// Columns count
Assert.AreEqual(1 , fc.Columns.Length , "FKC2");
}
示例11: ForeignKeyProviderBase
public ForeignKeyProviderBase(ITablePopulator foreignTable, ForeignKeyConstraint foreignKey)
{
if (foreignTable == null)
throw new ArgumentNullException("foreignTable");
if (foreignKey == null)
throw new ArgumentNullException("foreignKey");
this.foreignTable = foreignTable;
this.foreignKey = foreignKey;
isNullable = true;
foreach (DataColumn column in foreignKey.Columns)
{
if (!column.AllowDBNull)
{
isNullable = false;
break;
}
}
}
示例12: Ctor1
public void Ctor1 ()
{
DataTable Table = _ds.Tables [0];
AssertEquals ("test#01", 0, Table.Constraints.Count);
Table = _ds.Tables [1];
AssertEquals ("test#02", 0, Table.Constraints.Count);
// ctor (string, DataColumn, DataColumn
ForeignKeyConstraint Constraint = new ForeignKeyConstraint ("test", _ds.Tables [0].Columns [2], _ds.Tables [1].Columns [0]);
Table = _ds.Tables [1];
Table.Constraints.Add (Constraint);
AssertEquals ("test#03", 1, Table.Constraints.Count);
AssertEquals ("test#04", "test", Table.Constraints [0].ConstraintName);
AssertEquals ("test#05", typeof (ForeignKeyConstraint), Table.Constraints [0].GetType ());
Table = _ds.Tables [0];
AssertEquals ("test#06", 1, Table.Constraints.Count);
AssertEquals ("test#07", "Constraint1", Table.Constraints [0].ConstraintName);
AssertEquals ("test#08", typeof (UniqueConstraint), Table.Constraints [0].GetType ());
}
示例13: Equals
[Test] public void Equals()
{
DataSet ds = new DataSet();
DataTable dtParent = DataProvider.CreateParentDataTable();
DataTable dtChild = DataProvider.CreateChildDataTable();
ds.Tables.Add(dtParent);
ds.Tables.Add(dtChild);
dtParent.PrimaryKey = new DataColumn[] {dtParent.Columns[0]};
ds.EnforceConstraints = true;
ForeignKeyConstraint fc1,fc2;
fc1 = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);
fc2 = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[1]);
// different columnn
Assert.AreEqual(false, fc1.Equals(fc2), "FKC3");
//Two System.Data.ForeignKeyConstraint are equal if they constrain the same columns.
// same column
fc2 = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);
Assert.AreEqual(true, fc1.Equals(fc2), "FKC4");
}
示例14: Ctor1
public void Ctor1 ()
{
DataTable Table = _ds.Tables [0];
Assert.AreEqual (0, Table.Constraints.Count, "test#01");
Table = _ds.Tables [1];
Assert.AreEqual (0, Table.Constraints.Count, "test#02");
// ctor (string, DataColumn, DataColumn
ForeignKeyConstraint Constraint = new ForeignKeyConstraint ("test", _ds.Tables [0].Columns [2], _ds.Tables [1].Columns [0]);
Table = _ds.Tables [1];
Table.Constraints.Add (Constraint);
Assert.AreEqual (1, Table.Constraints.Count, "test#03");
Assert.AreEqual ("test", Table.Constraints [0].ConstraintName, "test#04");
Assert.AreEqual (typeof (ForeignKeyConstraint), Table.Constraints [0].GetType (), "test#05");
Table = _ds.Tables [0];
Assert.AreEqual (1, Table.Constraints.Count, "test#06");
Assert.AreEqual ("Constraint1", Table.Constraints [0].ConstraintName, "test#07");
Assert.AreEqual (typeof (UniqueConstraint), Table.Constraints [0].GetType (), "test#08");
}
示例15: AddRange
public void AddRange ()
{
_constraint1.ConstraintName = "UK1";
_constraint2.ConstraintName = "UK12";
ForeignKeyConstraint _constraint3 = new ForeignKeyConstraint ("FK2", _table.Columns [0],
_table2.Columns [0]);
UniqueConstraint _constraint4 = new UniqueConstraint ("UK2", _table2.Columns [1]);
// Add the constraints.
Constraint [] constraints = {_constraint1, _constraint2};
_table.Constraints.AddRange (constraints);
Constraint [] constraints1 = {_constraint3, _constraint4};
_table2.Constraints.AddRange (constraints1);
Assert.AreEqual ("UK1", _table.Constraints [0].ConstraintName, "A1");
Assert.AreEqual ("UK12", _table.Constraints [1].ConstraintName, "A2");
Assert.AreEqual ("FK2", _table2.Constraints [0].ConstraintName, "A3");
Assert.AreEqual ("UK2", _table2.Constraints [1].ConstraintName, "A4");
}