// Show all data using a LINQ query.
Console.WriteLine("-> Contents of Inventory Table from AutoLot database:\n");
foreach (var car in from c in invTable select c)
Console.WriteLine(car.ToString());
Console.ReadLine();
}
}
Notice that when
you create a DataContext type, you will feed
in a proper connection string,
which is represented here as a simple string constant. Of course, you are free to store this in an
application configuration file and/or make use of the SqlConnectionStringBuilder type to treat
this string type in a more object-oriented manner.
Next up, we obtain an instance of our Inventory entity class by calling the generic
GetTable() method of the DataContext type, specifying the entity class as the type parameter
when doing so. Finally, we build a LINQ query expression and apply it to the invTable object. As
you would expect, the end result is a display of each item in the Inventory table.
Do'stlaringiz bilan baham: