Alex Rivera | Logout

C# where does the dbml file come from?

Asked 2010-03-22T21:02:57.273
37

I am currently learning C# and LINQ. I have lots of questions about them. Basically, I need a step by step tutorial.

  1. I suppose the dbml file is the configuration file of the database. If I double click the dbml file VS will open it in a design diagram. Can I create/delete/modify tables here? I can use add new item to add the LINQ to SQL Classes to get a dbml file?

  2. What's next? Generate tables in database? Generate SQL script? Generate cs files? When? How?

Edit
Report

2 Answers

33

The DBML file is not related to the database server at all. It's a completely client side thing. It's essentially a set of information about your tables in the database and how you're going to map them to .NET objects.

Of course, you can drag a table from a database and have Visual Studio infer some information for you automatically, but changing the file will not affect the database. You can create a DBML file from scratch without any database too.

Internally, the DBML file is simply an XML file that's fed into a custom tool by Visual Studio and generates .cs files representing the LINQ object model for your database from it.

answered 2010-03-22T21:05:46.613
2

Yes, the DBML file is created when you add a Linq to SQL class. In the designer (what you see when you double click the DBML file) you can drag tables (from the server explorer) onto it. You can then reference these tables in your code. There are more than a few getting started tutorials out there:

Check this SO question for details:

https://stackoverflow.com/questions/481244/can-anyone-recommend-a-good-tutorial-for-learning-linq2sql

answered 2010-03-22T21:11:03.307

Your Answer