Best way to update LINQ to SQL classes after database schema change

前端 未结 7 2024
别那么骄傲
别那么骄傲 2020-11-29 16:08

I\'m using LINQ to SQL classes in a project where the database design is still in a bit of flux.

Is there an easy way of synchronising the classes with the schema, o

相关标签:
7条回答
  • 2020-11-29 16:24

    I haven't tried it myself, but Huagati DBML/EDMX Tools is recommended by other people.

    Huagati DBML/EDMX Tools is an add-in for Visual Studio that adds functionality to the Linq2SQL/DBML diagram designer in Visual Studio 2008, and to the ADO.NET Entity Framework designer in Visual Studio 2008 SP1. The add-in adds new menu options for updating Linq2SQL designer diagrams with database changes, for renaming Linq-to-SQL (DBML) and EF (EDMX) classes and properties to use .net naming conventions, and for adding documentation/descriptions to Linq-to-SQL generated classes from the database properties.

    Screenshot of DBML Tools

    0 讨论(0)
  • 2020-11-29 16:27

    I wrote a tool to do script changes to Dbml scripts see http://code.google.com/p/linqtodbmlrunner/ and my blog http://www.adverseconditionals.com

    0 讨论(0)
  • 2020-11-29 16:30

    How about modifying the Properties of the entity/table within the DataContext design surface within Visual Studio?

    For instance if I added a column to an SQL Server table:

    1. Open the *.dbml file.
    2. Right click the entity and select Add > Property.
    3. Fill out the values in the Properties window for the new column.
    4. Build your solution.

    The auto generated model classes should reflect the new column that was added.

    0 讨论(0)
  • 2020-11-29 16:31

    I think Jeff complained about this recently. One common technique is to drag all the objects into the designer again...

    I hope someone else chimes in with a better approach!

    0 讨论(0)
  • 2020-11-29 16:33

    DamienG has written some t4 templates which can replace some of what VS generates for you. These can be rerun whenever you like via a command line tool.

    T4 templates have the added benefit of being editable. This allows you to tweak what is generated to you hearts content.

    0 讨论(0)
  • 2020-11-29 16:35

    You can use SQLMetal.exe to generate your dbml and or cs/vb file. Use a pre-build script to start it and target the directory where your datacontext project belongs.

    C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64\sqlmetal.exe 
      /server:<SERVER> 
      /database:<database> 
      /code:"path\Solution\DataContextProject\dbContext.cs" 
      /language:csharp 
      /namespace:<your namespace>
    
    0 讨论(0)
提交回复
热议问题