Visual-studio – LINQ to SQL: Multiple / Single .dbml per project

linqlinq-to-sqlvisual studio

I've read Rick Strahl's article on Linq to SQL DataContext Lifetime Management hoping to find some answers on how I would manage my .dbml files since they are so closely related to DataContext. Unfortunately, Rick's article seems to be focused on DataContext lifetime at runtime though, and my question is concerned with how the .dbml's should be organized at design time.

The general question of 'Best practices with .dbml's' has been asked and answered here, and the answers have focused on external tools to manage the .dbml.

I'm asking a more focused question of when and why should you not have a single .dbml file in your LINQ to SQL based project?

Best Answer

Please note that LINQ2SQL is intended for simple and easy way to handle database relationship with objects.

Do not break table relationship and units of work concepts by creating multiple .dbml files.

If you ever need to create multiple .dbml files (which i don't recommend), then try to satisfy the following:-

  1. If you create multiple databases with no relationship between those database tables.
  2. If you want to use one of these .dbml just to handle stored procedures
  3. If you do not care about unit of work concept.

If your database is too complex, then I would consider ORM such as NHibernate, EF 4

Related Topic