如何阻止linq设计师覆盖我的手动更改?

时间:2022-01-14 20:44:08

I like Linq but find that once the designer has created my classes I have to modify them. Then when I change my database and recreate my classes in the designer my changes get wiped.

我喜欢Linq,但发现设计师创建我的课后我必须修改它们。然后,当我更改我的数据库并在设计器中重新创建我的类时,我的更改将被删除。

For instance, let's say I have a class called Person. I create this class, add some non database related methods to it (outside of Linq) and then create a database table with a similar name. Linq will duplicate this class in the designer.cs file when I drag it in.

例如,假设我有一个名为Person的类。我创建这个类,向它添加一些非数据库相关的方法(在Linq之外),然后创建一个具有类似名称的数据库表。当我将它拖入时,Linq将在designer.cs文件中复制此类。

So I go and add the partial keyword to the class in that file or even change the class name Linq created. As development proceeds, no doubt the database table changes and I have to redrag my tables into the designer. Voila, my manual changes get wiped.

所以我去将partial关键字添加到该文件中的类中,甚至更改Linq创建的类名。随着开发的进行,毫无疑问数据库表会发生变化,我必须将表格重新划分为设计器。瞧,我的手动变化被抹去了。

This is most annoying! In fact, its unworkable to keep modifying code I have already modified.

这是最烦人的!事实上,继续修改我已经修改过的代码是不可行的。

Any suggestions?

1 个解决方案

#1


Create a partial class for your context and make your changes there, the designer generated .cs files are recreated every time you click save.

为您的上下文创建一个部分类并在那里进行更改,每次单击“保存”时都会重新创建设计器生成的.cs文件。

#1


Create a partial class for your context and make your changes there, the designer generated .cs files are recreated every time you click save.

为您的上下文创建一个部分类并在那里进行更改,每次单击“保存”时都会重新创建设计器生成的.cs文件。