从生成的类中删除成员变量 [英] Drop Member Variable from Generated Class

查看:69
本文介绍了从生成的类中删除成员变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

我希望从我从Entity Framework Core生成的一个生成的类中删除导航成员变量。现在,如果我删除导航变量,我在调用LINQ方法时会出现SQL异常错误。我有一个简单的方法可以删除其中一个导航变量吗?

I am looking to remove a navigation member variable from one of my generated classes that were generated from Entity Framework Core. Right now, if I remove a navigation variable, I get a SQL exception error when I call a LINQ method. Is there an easy way for me to remove one of these navigation variables?

谢谢

推荐答案

Sam_Mallabone,

Hi Sam_Mallabone,

感谢您在此处发布问题。

Thank you for posting the problem here.

根据您的描述,您希望从现有数据库生成的某些类中删除导航属性。

According to your description, you would like to deleted a navigation property from some classes which are generated from existing database.

对于您的某些导航变量生成的类,它们映射您的外键并表示生成的类的关系。

For some navigation variables in your generated classes, they map your foreign keys and represent the relationship of your generated classes.

根据您之前的主题,您希望从生成的SerialNumbers类中删除用户和合同导航变量。如果您的代码中未使用用户表和合同表,则可以执行以下命令在包管理控制台上生成类

According to your previous thread, you would like to remove User and Contract navigation variables from generated SerialNumbers class. If the User Table and Contract Table are not used in your code, you could execute the following command to generate classes on Package manage console.

Scaffold-DbContext "Server=VDI-V-JIANPW\SQLEXPRESS;Database=FirstDatabase;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -t ("SerialNumbers "," Features")

用户和合约导航变量不会是在你的SerialNumbers类中生成。

The User and Contract navigation variables will not be generated in your SerialNumbers class.

如果你想生成User和Contract类,我做了一个测试,我从生成的类中直接删除了导航属性(不是更新数据库。)并执行选择并插入操作。它运作良好。

If you want to generate User and Contract classes, I made a test which I directly deleted a navigation property ( not update database.)from a generated class and executed select and insert operations. It worked well.

>>当我调用LINQ方法时出现SQL异常错误。

你能指出例外吗?

>> I get a SQL exception error when I call a LINQ method.
Could you please indicate the exception?

如果你能提供一个可以再现问题的演示,我会更好,更快地帮助你。

If you could provide a demo which reproduces your problem, I will help you better and faster.

我很乐意帮助你你好。

最好的问候,

Cole


这篇关于从生成的类中删除成员变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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