none
Include SqlMetal inside C# .Net DL project RRS feed

  • Question

  • Hello,
      I have a .bat file that creates the dbml  I would like to run it and replace the .dbml file inside the project.  Is there a way to do that.
    Friday, October 16, 2009 12:15 PM

Answers

  • You can execute SqlMetal from the pre-build tasks directly in VS without a batch file.

    The DBML is only to allow customization before the code is generated. You'll also need to generate the .cs/.vb file - you can do this from SQLMetal too.

    You might want to consider using SQLMetal to generate the DBML then use the LINQ to SQL T4 templates to generate the code. These templates come with full source so you can modify them to apply your isprimarykey code to the generate code instead of hand-modifying the DBML.

    [)amien
    • Marked as answer by Mattaniah Tuesday, October 20, 2009 11:57 AM
    Monday, October 19, 2009 3:19 PM
    Moderator

All replies


  • Just delete the previous dbml with the server explorer, then add an existing item, at the "Add Existing Item" dialog, set "All Files (".")" under the name textbox, you will see the new dbml, dobleclick on it...


    Believe you can do it, and you will!!
    Friday, October 16, 2009 3:56 PM
  • You could write a macro, or add-in that does that for you.
    Macros are relatively simple to write (though I believe you can only write them in VB). The EnvDTE (EnvDT80 for VS2005, EnvDTE90 for VS2008) automation library encapsulates Visual Studio. Sorry I can't give a sample directly related to what you wish to do but there's a lot of documentation available on MSDN.
    Friday, October 16, 2009 4:34 PM
  • Are you trying to recreate your DBML while you are developing the application or hoping to replace it at run-time on a users machine?

    [)amien
    Saturday, October 17, 2009 3:24 AM
    Moderator
  • I would like to execute the .bat file before the project builds sucessfully and replace the existing .dbml with the new .dbml.  This is instead of manually deleting the old one, running the .bat, then adding the file to the project. 
    BTW, I have a series of views that I must add isprimarykey="true" to each time I regenerate the .dbml.  Is there a way to do that programmatically through a .bat file?

    thanks
    Monday, October 19, 2009 10:40 AM
  • You can execute SqlMetal from the pre-build tasks directly in VS without a batch file.

    The DBML is only to allow customization before the code is generated. You'll also need to generate the .cs/.vb file - you can do this from SQLMetal too.

    You might want to consider using SQLMetal to generate the DBML then use the LINQ to SQL T4 templates to generate the code. These templates come with full source so you can modify them to apply your isprimarykey code to the generate code instead of hand-modifying the DBML.

    [)amien
    • Marked as answer by Mattaniah Tuesday, October 20, 2009 11:57 AM
    Monday, October 19, 2009 3:19 PM
    Moderator