Each database table is represented as a Table collection, which is available through the GetTable method
of the DataContext class. GetTable gives you access to the table in an untyped fashion. For example, the
following code creates a connection to the AdventureWorks database and the Contact table by way of
the GetTable method, but it is not strongly typed:
DataContext context = new DataContext(
"Initial Catalog=AdventureWorks;Integrated Security=sspi");
Table
con = context.GetTable();
The appropriate way to create a strongly typed DataContext is:
public class AdventureWorks : DataContext
{
public AdventureWorks(string connection) : base(connection) {}
public Table Contact;
}
This example creates a new class that inherits from the DataContext class and then defines a table for
a specific type (in this case, the Contact table) in the underlying database. This provides access to the
database through a strongly typed DataContext and strongly typed table.
Data Manipulation
Now you??™re ready to start querying, modifying, and sending data back to the database.
Pages:
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363