执行“从数据库更新模型"时,如何防止我的模型文件被刷新? [英] How can I keep my model files from being refreshed when doing an "Update Model from Database"?

查看:41
本文介绍了执行“从数据库更新模型"时,如何防止我的模型文件被刷新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 Entity Framework Database First 风格开发的项目.我对各种模型文件进行了一些更改,现在每次我对 EDMX 文件执行从数据库更新模型"时,这些更改都会消失.我看到有一个刷新选项卡,它列出了我的模型文件,但无法告诉 VS 不刷新这些文件.我应该在这里做什么?谢谢.

I have a project that uses Entity Framework Database First style development. I made some changes to various Model files, and now every time I do an "Update Model from Database" on my EDMX file, those changes get wiped out. I see there is a tab for Refresh and it has my model files listed, but there is no way to tell VS to not refresh these files. What should I do here? Thanks.

推荐答案

不要将更改直接写入 .edmx 类.这些类是由 ef 生成的.生成的类定义为部分类,以便您可以在单独的物理文件中定义自己的部分类以扩展生成的功能.

Don't write your changes directly to the .edmx classes. Those classes are generated by ef. The generated classes are defined as partial so that you can define your own partial class in a separate physical file to extend the generated functionality.

这是一个很好的例子

https://dotnetcodr.com/2015/02/18/extending-class-definitions-with-partial-classes-in-c-net/

它甚至会在生成的 .cs 文件的顶部声明

It even states at the top of the generated .cs file

//------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated from a template.
//
//    Manual changes to this file may cause unexpected behavior in your application.
//    Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

这篇关于执行“从数据库更新模型"时,如何防止我的模型文件被刷新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆