[Table(Name = "Person.Contact")]
public class Contact
{
[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;
}
At this point, the relational mapping is complete, having mapped a data model to an object model.
The next step is to build the channel by which the objects and data are retrieved from the database. The
channel is created via the DataContext class. The DataContext class is part of the System.Data.Linq
namespace, and its purpose is to translate your requests from .NET objects to SQL queries, and then
reassemble the query results back into objects.
The DataContext class is discussed in detail in Chapter 11.
Here??™s an example that defines a DataContext that connects to the Adventureworks database using
integrated security:
DataContext context = new DataContext(
"Initial Catalog=AdventureWorks;Integrated Security=sspi");
200
Chapter 10: LINQ to SQL Overview
You use DataContext much the same way that you use an ADO.
Pages:
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331