Now modify the
Remove() statement so that it reads as follows:
db.Customer.Remove(soh);
When this code is executed, it will cause an error.Why? Because there is a foreign key constraint between
the Customer table and the SalesOrderHeader table on the CustomerID column.
Designer Example
Hopefully, the Visual Studio project that you created earlier is still open. In this example, you use the
O/R Designer to create a LINQ to SQL entity and bind that entity to a Windows form.
First, open the O/R Designer by double-clicking the AdventureWorksSales.dbml file in the Solution
Explorer. Now, as you learned previously, you can create entity classes based on objects in the database.
Open the Server Explorer and expand the connection to the AdventureWorks database you created
earlier. Expand the Tables node and drag the Contact table into the entity pane.
Next, from the Data menu on the main menu bar, select Add New Data Source. That opens the Data
Source Configuration Wizard dialog shown in Figure 15-17.
The wizard enables you to create entity classes as a data source.
Pages:
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484