在用作条件的情况下,如何更改鉴别器(__Disc__)字段 [英] How can I change Discriminator (__Disc__) field while it is used as a condition
问题描述
我必须更新和更改表的Discriminator( _ Disc _ )字段,而映射的实体没有将其作为实体成员强>.有什么解决办法吗?
I have to update and change Discriminator(_Disc_) field of a table while mapped entities doesn't have it as an entity member. any solution?
推荐答案
Discriminator列用于定义TPH继承中的实体类型,EF不能更改它-永远不会.这就像在任何面向对象的语言中进行继承一样-一旦定义了某种类型的对象,就不能将其设置为其他类型-您只能将其强制转换为父类,但它仍将是原始类型的实例.将其更改为其他类型的唯一方法是创建新类型的新实例,然后以某种方式将值从第一个对象复制到新对象.
Discriminator column is used to define type of entity in TPH inheritance and EF cannot change it - never. It is like inheritance in any object oriented language - once you define object of some type you cannot make it different type - you can only cast it to parent but it will still be instance of original type. The only way to change it to different type is to create a new instance of the new type and somehow copy values from the first object to the new one.
因此,如果您需要更改区分符,则必须使用旧的ADO.NET和SQL在不使用EF =的情况下进行操作,但是如果您的更改不遵循实体模型中的其他规则,则会破坏EF功能,并且您的应用程序将无法运行.
So if you need to change discriminator you must do it without EF = by using old ADO.NET and SQL but if your change will not follow other rules in your entity model you will break EF functionality and your application will not work.
这篇关于在用作条件的情况下,如何更改鉴别器(__Disc__)字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!