The following example illustrates how to map a few properties with several columns of the
Person.Contact table in the Adventureworks database:
[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;
[Column(DBType = "nvarchar(50)")]
public string EmailAddress;
[Column(DBType = "int")]
public int EmailPromotion;
Add this to the Table mapping, and you have the following:
[Table(Name = "Person.Contact")]
public class Contact
{
[Column(DBType = "nvarchar(8) not null")]
public string Title;
[Column(DBType = "nvarchar(50) not null")]
public string FirstName;
[Column(DBType = "nvarchar(50) not null")]
public string MiddleName;
[Column(DBType = "nvarchar(50) not null")]
public string LastName;
[Column(DBType = "nvarchar(50) not null")]
public string EmailAddress;
[Column(DBType = "int")]
public int EmailPromotion;
}
Only those columns that are defined are used to persist data to the table and retrieve data from the
database.
Pages:
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339