How to override Equals on a object created by an Entity Data Model?

主宰稳场 提交于 2019-12-08 16:16:30

问题


I have an Entity Data Model that I have created, and its pulling in records from a SQLite DB. One of the Tables is People, I want to override the person.Equals() method but I'm unsure where to go to make such a change since the Person object is auto-generated and I don't even see where that autogen code resides. I know how to override Equals on a hand made object, its just where to do that on an autogen one.


回答1:


You need to create a partial class. Add a new .cs file to your solution, and start it like this:

public partial class Person
{
    public override bool Equals(Object obj)
    {
        //your custom equals method
    }
}



回答2:


You can try using partial classes - I think you can find autogenerated code in the solution. If you find out that Equals is not overriden by default and generated class is partial (I think it should be partial) than you can add another file to your solution and place partial class with implenentation of Equals there:

public partial class Person
{
    // Your override of Equals here
}


来源:https://stackoverflow.com/questions/2472441/how-to-override-equals-on-a-object-created-by-an-entity-data-model

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