Building a Strongly Typed DataContext
While our first example is strongly typed as far as the database query is concerned, we do have a bit
of a disconnect between the DataContext and the Inventory entity class it is maintaining. To remedy
this situation, it is typically preferable to create a class that extends the DataContext type that
defines member variables for each table it operates upon. Insert a new class called AutoLotDatabase,
specify you are using the System.Core and System.Data.Linq namespaces, and implement the type
as follows:
class AutoLotDatabase : DataContext
{
public Table Inventory;
public AutoLotDatabase(string connectionString)
: base(connectionString){}
}
With this new class type, we are now able to simplify the code within Main() quite a bit:
static void Main(string[] args)
{
Console.WriteLine("***** LINQ to SQL Sample App *****\n");
Do'stlaringiz bilan baham: |