I have a Linq to Sql Model generated by VS ORD, but I want to make a changes to it to work around a couple of issues. I can change the designer.cs generated code , but if I ever need to recreate a table within the model, then I delete it and drag it back to the ORD. This however loses all of my customisations. Is there another way?
I have seen reference to sqlMetal.exe, but not sure how I would use this to get around the issue.
For information my customisations are as follows:
- I am using
Guid‘s and want the db to default these values, therefore I want to change the default linqtosl behaviour to add the attribute[Column(IsDbGenerated= true)]to the ID properties. - the Default Model Binding for MVC is not working for a collection (
EntitySet<T>). To work around this I need to change the setter for these collections slightly.
Neither of these changes are particularly big, but my database could change considerably over time, and I need to remember to do each customisation each time.
I’ve had this same question and was hoping to see an answer appear here that solves both of the points you mention. (I found another workaround to your item #2, although your idea of using OnCreated() in a partial seems nicer than what I’m currently doing.)
I did run across an article recently (which I’ll link to below) which might be an applicable solution to achieve these goals. This article describes how the author (1) uses SQLMetal to generate a dbml file, (2) runs a custom process which parses and modifies this dbml file to suit his needs, then (3) uses SQLMetal again, this time feeding in the modified dbml file, in order to generate code. It may be a lot of work for small projects/schemas, but I could see how this might be a handy workaround on large projects.
Here’s the link: http://www.onedotnetway.com/enum-support-with-linq-to-sql-and-sqlmetal/
Best of luck!
-Mike