Contact. In it, the
ContactID column is mapped and annotated as a column to return. In the definition of the column,
several properties are set, identifying it as the primary key of the Person.Contact table, and enabling its
values to be generated automatically (via the IsDBGenerated property).
[Table(Name = "Person.Contact")]
public class Contact
{
[Column(DBType = "int", IsPrimaryKey = true, IsDBGenerated = true)]
public int ContactID;
[Column(DBType = "nvarchar(8)")]
public string Title;
[Column(DBType = "nvarchar(50) ")]
public string FirstName;
[Column(DBType = "nvarchar(50) ")]
public string MiddleName;
[Column(DBType = "nvarchar(50) ")]
public string LastName;
211
Part III: LINQ to SQL
[Column(DBType = "nvarchar(50) ")]
public string EmailAddress;
[Column(DBType = "int")]
public int EmailPromotion;
}
Any time you are mapping a relational table that has a primary key, and you plan on returning the
primary key column in your LINQ to SQL queries, you must identify the column as the primary key and
the identity by using the properties IsPrimaryKey and IsDBGenerated as this example shows.
Pages:
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349