EF 4, how to add partial classes

亡梦爱人 提交于 2019-11-29 07:20:26

To summarise the large comment trail...

Check that the partials are being attached together correctly:

  • Make sure that both class definitions are in the same namespace and assembly.
  • Make sure at least one of them is declared as partial (most generated classes are, including EF generated ones).
  • Check to make sure that the newly created partial can see the previous members, to confirm the partials match up.

Where the client is in a different binary (which was the case here)

  • Make sure the client projects binary/references are up to date (perform a clean build / delete the binary copy / recreate the reference), depending upon your project situation.

For this case, the last check was the most important and solved the problem.

You should make sure that:

public partial class CAR 
{
    private int _sequences;
    public int sequences
    {
        get { return _sequences; }
        set { _sequences = value; }
    }
}

In your generated EF class you are required to:

public partial class CAR 
{
}  
  1. Add partial keyword to the EF generated class.
  2. Make sure they reside in the same namespace.

Create a new class in a separate file in the same assembly (although it doesn't have to be the same assembly) and make sure it has the same namespace.

If they are both in the same assembly and namespace you shouldn't have any issues. You'll know that you've got it right when the new partial you've created can see the properties and methods of the generated EF class in the dropdown at the top of the source code editor.

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