Sorry for the slow reply.
I seem to be unable to duplicate building the "Customer Table". When I open the toolbox and click on Class, I get a class object with no records in the class.
Please elaborate on the procedure on Page 438, if it is relevent for a Access database, and Page 432 para.4 and beyond.
Do you mean page 428 instead of 438? I think that code should work after you create the LINQ to SQL classes for your database not matter what kind of database it is.
That code:
- Creates a data context to represent an attachment to the database.
- Creates a new Customer object.
- Calls the context's InsertOnSubmit method to get it ready to add the new record.
- Calls the context's SibmitChanges method to make the addition.
If that's not the code you're looking at, let me know.
The Customer class represents records in the table. If you create a new instance of the class, you're creating an object that *could* be stored in the table but it has not been stored there yet. You need to call InsertOnSubmit and SubmitChanges to add the new record to the table.
You should be able to use LINQ queries to get records from the table as shown on Page 429. The data context provides access to the tables. For example, the second piece of code on page 429 selects data from db.Customers. This is the Customers table in the database.
Normally you would build the database and its tables, possibly with some initial data, in a database tool such as Access or SQL Server's Management Studio. I'm pretty sure that's what I did.
To set up for using Access, follow the steps on page 432. They are briefly:
- Create a new project.
- In the File menu, select Add New Item, select "LINQ to SQL Classes," and click OK.
- Add a class object to the designer. Initially it has no fields. Right-click on it and select "Add Property" to add a properties such as FirstName, LastName, or whatever you want in the class. These should match the fields in the database table. For example, if this is a Customer class, make it match the Customers table.
- Click on the class's properties and use the Properties window to set the properties of the properties. For example, set Nullable, PrimaryKey, Server Data type, etc.
When you're done creating the classes, then I think you can use code similar to what's shown on Page 433 to connect to the database.
I hope that helps but I'm not sure if I've answered your question. If not, post again to let me know where you're stuck and I'll try to provide more detail.
(BTW, if you're going to do a lot of this in real applications, as opposed to just for learning purposes, then you might want to consider installing SQL Server Express Edition. It's a little harder to administrate than Access but it uses Microsoft's preferred database connection methods so a lot of the code works more easily with it than with Access and other database types. And SQL Server Express Edition is basically a slightly restricted version of SQL Server so if you ever decide you need to move to the less restricted version you can without rewriting a lot of code.)