How to update only one table for model from database with Entity Framework?

后端 未结 3 2037
悲哀的现实
悲哀的现实 2021-02-02 07:53

I have a model generated from db with Entity Framework. When I have any change in database, I update model from database to get the change in model. But this update is applied t

相关标签:
3条回答
  • 2021-02-02 08:10

    The EDMX file is an XML file that is a combination of 3 different parts that make up the whole thing. If you right-click on your EDMX file and choose "Open with... XML Editor" you'll see the 3 different sections:

    • <edmx:ConceptualModels>
    • <edmx:StorageModels>
    • <edmx:Mappings>

    These sections can be edited manually, at your own risk! :-)
    That way you can modify only what you need to.

    Note that it's also possible to generate CSDL, SSDL & MSL files rather than having them embedded in the binary file, by changing the "Meta Artifact Processing" property of your model to "Copy to Output Directory".

    If you don't want to do this manually, there's the Huagati DBML/EDMX tool, it is free and you can download it from huagati official site or from visual studio gallery, which is a Visual Studio plugin that allows you to select what changes need to be done.

    0 讨论(0)
  • 2021-02-02 08:12

    I use following (Conditional) trick. This could be done only when no Table depends on the table which you want to update.

    1. Delete the table which needs to be updated.
    2. Right click on Model and select 'Update Model From Database'. The Table would be shown in the tab 'Add'. Select this table and Update the model.

    Precaution : If other existing tables have changes in them, EF would update these changes as well.

    0 讨论(0)
  • 2021-02-02 08:15

    There is way of doing it automatically.

    right click edmx file > update model from data base > Refresh tab > Tables > select the table(you want to update) and press finish that's it.

    0 讨论(0)
提交回复
热议问题