Search code examples
c#asp.netentity-frameworkpocoentityobject

Switch to using POCOs instead of EntityObjects


I would like to start by saying that im new to EF, and the following text is just based on my assumptions. So feel free to correct me on where im wrong:

I have an entity generated by EF called Foo. I suppose this is an EntityObject. So if i create an instance of Foo, it will be an EntityObject.

But if i create a new partial class called Foo in my Entity Modifications folder, i will have a POCO version of it. I would like to know how to use the POCO instead of the EntityObject.


Solution

  • Suppose you have the following:

    public partial class Foo : EntityObject { }
    

    and

    public partial class Foo {}
    

    This will result in one class Foo that inherits from EntityObject. The partial keyword does not mean that you have multiple classes Foo, it means that you have one class Foo that is divided over several code files and the compiler will merge them for you. Here you can find some more documentation.

    If you don't want to inherit from EntityObject but have real POCO's you should have a look at the T4 templates for generating POCO entities.