<p>I've just started using Linq to SQL, and I'm wondering if anyone has any best practices they can share for managing dbml files.</p>

<ul>
<li>How do you keep them up to date with the database?</li>
<li>Do you have a single dbml file for the entire database, or is it split into multiple logical units?  </li>
<li>How does managing this file work in a team environment?</li>
</ul>

<p>Any other tips and tricks welcome.</p>

[{'answer_id': 33667, 'author': 'Kevin Dente', 'author_id': 9, 'author_profile': 'https://Stackoverflow.com/users/9', 'pm_score': 3, 'selected': False, 'text': '<p>The fact that the L2S designer doesn\'t support syncing with the database structure is a huge limitation in my mind. However, there is an add-in available that provides some re-sync capabilities:</p>\n\n<p><a href="http://www.huagati.com/dbmltools/" rel="nofollow noreferrer">http://www.huagati.com/dbmltools/</a></p>\n\n<p>Unfortunately, it\'s no longer free.</p>\n'}, {'answer_id': 36749, 'author': 'Gareth Jenkins', 'author_id': 1521, 'author_profile': 'https://Stackoverflow.com/users/1521', 'pm_score': 5, 'selected': True, 'text': '<p>Have you looked at <a href="http://msdn.microsoft.com/en-us/library/bb386987.aspx" rel="nofollow noreferrer">SqlMetal</a>? It\'s officially supported, although not promoted too much. You can use it to build dbmls from the commandline - we\'ve used it as part of a db\'s continous integration updates (make sure you have really good code separation if you do this though  - partial classes are a saviour - as the dbml will get overwritten).</p>\n\n<p>If I recall correctly it doesn\'t have quite the same features as the model designer in Visual Studio (I think it handles pluralisation differently). There a <a href="http://blog.benhall.me.uk/2007/08/power-of-sqlmetal.html" rel="nofollow noreferrer">good post about it on Ben Hall\'s blog</a>.</p>\n'}, {'answer_id': 1196791, 'author': 'Shannon Davidson', 'author_id': 103596, 'author_profile': 'https://Stackoverflow.com/users/103596', 'pm_score': 3, 'selected': False, 'text': '<p>PLINQO is a set of code generation templates generating LINQ to SQL.  It supports syncing with the database and splitting entities into multiple classes along with many other features that make LINQ to SQL easy to use.</p>\n\n<p>Check out the PLINQO site at <a href="http://www.plinqo.com" rel="nofollow noreferrer">http://www.plinqo.com</a> as well as the intro videos.</p>\n'}, {'answer_id': 1790664, 'author': 'Alison R.', 'author_id': 59870, 'author_profile': 'https://Stackoverflow.com/users/59870', 'pm_score': 3, 'selected': False, 'text': '<p>Since you asked for other tips and tricks for managing DBML...</p>\n\n<p>When DBML files are refreshed from the database, there are certain schema settings which they don\'t pick up on, such as default column values, forcing you to manually change the setting. This can lead to lost hours every time you refresh the DBML without realizing or remembering where you need to make manual adjustments, and your code starts failing.</p>\n\n<p>To guard against this, one trick is to write a unit test which uses reflection to check the LINQ metadata for those (manual) settings. If the test fails, it gives a descriptive error message, instructing the user to make the proper change to the column properties. It\'s not a perfect solution, and it might not be convenient if you have many manual settings, but it can help avoid some major pain for yourself and your team.</p>\n\n<p>Here\'s an example of an nunit test to check that a column is set to auto-generate from the DB.</p>\n\n<pre><code>    [Test]\n    public void TestMetaData()\n    {\n        MyObj my_obj = new MyObj()\n        {\n            Foo = "bar",\n        };\n\n        Type type = MyObj.GetType();\n        PropertyInfo prop = type.GetProperty("UpdatedOn");\n        IEnumerable&lt;ColumnAttribute&gt; info = (IEnumerable&lt;ColumnAttribute&gt;)prop.GetCustomAttributes(typeof(ColumnAttribute), true);\n        Assert.IsTrue(\n            info.Any&lt;ColumnAttribute&gt;(x =&gt; x.IsDbGenerated == true), \n            "The DBML file needs to have MyObj.UpdatedOn AutoGenerated == true set. This must be done manually if the DBML for this table gets refreshed from the database."\n        );\n    }\n</code></pre>\n'}, {'answer_id': 3880555, 'author': 'rs.emenu', 'author_id': 442131, 'author_profile': 'https://Stackoverflow.com/users/442131', 'pm_score': 2, 'selected': False, 'text': '<p>Here is a link that provides good information about LINQ to SQL best practices</p>\n\n<p><a href="http://www.a2zmenu.com/LINQ/LINQ%20to%20SQL%20Best%20Practice.aspx" rel="nofollow">http://www.a2zmenu.com/LINQ/LINQ%20to%20SQL%20Best%20Practice.aspx</a></p>\n'}]
['https://Stackoverflow.com/questions/33664', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/637/']