views:

52

answers:

3

I'm generating domain model using LINQ to SQL via the VS2008 built-in editor. That works really well, too; when I adjust my database schema I simply delete everything from the editor and then pull it back in from the server explorer by selecting all tables and dragging them into the designer surface. That works great too.

Now the problem: I have properties that I manually set to autogenerated, readonly etc. using the property inspector on the right. Everything I re-create the entire schema I have to do this manually all over again.

Is there a way to persist these settings externally and/or automate them to bring it back to the state from before?

+1  A: 

T4 Toolbox has a Linq to Sql Schema generator which allows you to develop your Linq to Sql applications in a model first approach. I have used it a little and it works really well, here is a blog post with details and usage info.

Simon Fox
+1  A: 

You can use something like the Huagati DBML Tools. This will allow you to update the DBML file from the VS designer.

I've also used the following process before:

  1. Create my schema in SSMS
  2. Create a script that uses the SQL Metal command line tool to generate the DBML file
  3. As the DBML file is XML, you can run transformations on the file. I used this to simply change a few things like setting certain fields to be auto-generated (DateCreated, etc).
  4. Then, either use SQL Metal or T4 to create the model files from the altered DBML file.

This process worked great - however I had complete control over the database schema. This process also allowed me to use L2S with SQL Server Compact Edition.

Hope this helps!

Brad Leach
A: 

Your solution may appear to work when you have very few database entities / tables, but it does not scale and as you've found, syncing is less than ideal.

Do not use the Visual Studio 2008 LinqToSql O/R Designer

After looking at many alternatives to the problems you are describing with LinqToSql, I decided to abandon LinqToSql altogether as I didn't find any of the workarounds very good. Competing ORMs don't have the silly problems that LinqToSql has and they are much more mature and feature rich.

I could/should probably list some of the alternatives I ran across, but I don't want to spend the time and give you false hope, sorry.

Michael Maddox