How can I change Discriminator (__Disc__) field while it is used as a condition

断了今生、忘了曾经 提交于 2019-12-12 22:54:26

问题


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?


回答1:


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.

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.



来源:https://stackoverflow.com/questions/8668678/how-can-i-change-discriminator-disc-field-while-it-is-used-as-a-condition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!