I am trying to get an understanding of what poco generators in .NET are supposed to do. In my opinion, they should be code generation tools that will allow me to select entities from my edmx file that I want to create a POCO for and generate classes based on the table's fields while allowing me to customize the generated poco name so it is different from the class name generated in my edmx designer.cs file. Say for eg: I have a table called Customer which in the edmx file gets named as Customers. Now the poco generation tool should allow me to create a class called say, BusinessCustomers.
However, while they do that bit of generating classes without allowing me to customize the generated class name, I have noticed that when generating such pocos from this example, they tend to be classes that are still owned by the code generation tool. The generated poco class is a partial class named as Customers, which is basically an Extension of the edmx class. I cannot selectively choose what entities I want to generate pocos for. So in case I have made changes to the generated class they will be lost anytime I add new tables to the edmx file and want to create new pocos using the tool. I can of course copy the generated classes to another project and use them from there, but I am not sure if that is the right way. In my example above, the generated poco class is a partial class named as Customers, with virtual properties, one for each field in the table. The edmx designer.cs is wiped clean. I am still going to be using a class generated by the tool in my code. If I want a separate poco class I will still have to write it myself... Wasn't the poco generator supposed to create a new set of classes for me leaving the edmx classes intact?
At the bare minimum all I want is the tool to generate classes for me and not touch it again once it is done with generating it. If I have understood the ADO.NET C# POCO Entity Generator correctly, it doesn't do the job like that. Are there better tools out there or should I just stick to hand coding my poco classes for my requirements? What do you think?
Sorry if my question is a bit confusing; I am writing this with limited and perhaps incorrect understanding of the subject . Thanks for your time ...
POCO class generators are there to help you customize the generation process by altering the T4 template that generates them and also break them apart from the EDMX containing project. This can be really helpful for say testing, where you replace the EDMX with a custom generator or some other data feeding structure that populates your generated classes which can be in a wholly different project than the edmx itself.
As for customization all you have to do is declare those classes as Partial (not sure if that's the default, but can easily alter that in the T4 template). So what you do is have another file representing the part of the class holding the custom code. That way you can customize your classes without loosing changes when re-generating them.
So long answer short, you should stick with POCO Generator, as it simplifies the whole process of mapping DB tables to classes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With