Defining Relationships Using Entity Classes
Beyond simply defining properties with backing fields to represent data table columns, the
sqlmetal.exe utility will also model the relationships between interrelated tables using the
EntitySet type. Recall from Chapter 22 that the AutoLot database defined three interrelated
tables, connected by primary and foreign keys. Rather than forcing us to author SQL-centric join
syntax to navigate between these tables, LINQ to SQL allows us to navigate using the object-centric
C# dot operator.
To account for this sort of table relationship, the parent entity class may encode the child table
as property references. This property is marked with the [Association] attribute to establish an
association relationship made by matching column values between tables. For example, consider
the (partial) generated code for the Customer type, which can have any number of orders:
[Table(Name="Customers")]
public partial class Customers :
INotifyPropertyChanging, INotifyPropertyChanged
{
private EntitySet _Orders;
Do'stlaringiz bilan baham: |