Adding a Quick LINQ to SQL Database in Visual Studio 2010

Adding a Quick LINQ to SQL Database in Visual Studio 2010

Here is a quick way to insert a LINQ to SQL database in a Visual Studio 2010 project.

  1. Go to Tools -> Connect to Database.
  2. Click on Browse.
  3. Browse to desired directory and database file.
  4. If creating a new database, type in the new database name (including the .mdf extension).
  5. Click Open.
  6. If you opened an existing database, skip steps 7-9.
  7. Browse in Server Explorer to the new database. Expand it and go to the Tables folder.
  8. Right click on the Tables folder and Add New Table
  9. Fill out the table.
  10. Click OK.
  11. You will get a window that says “The database file ‘location of file’ does not exist. Would you like to create it?. Click Yes.
  12. Go to Project -> Add New Item.
  13. Click LINQ to SQL Classes. Give it a name.
  14. The Object Relational Designer window shows.
  15. Navigate in the Server Explorer to the database Table folder.
  16. Drag and Drop a table to the ORD window. A window will pop up and click Yes.
  17. Do this to all your tables.
  18. You now have access to the database using LINQ to SQL classes.

1 Comment

Leave a Reply