Diego Vega's blog

Entity Framework news and sporadic epiphanies

EF Design Post: POCO template generation options

EF Design Post: POCO template generation options

  • Comments 2

It has been some time since the last time my team posted anything to the Entity Framework Design blog. The truth is we have been extremely busy finishing the work on Entity Framework 4.

It feels great to be almost done! And now one of my favorite phases of the product cycle begins, again... How to best address the needs of our customers with the people we have, in the time we have, with the highest quality we can achieve? How do we test this design? How do we implement this hard piece? How do we make the API make sense as a whole?

As we start putting together more design ideas, we will need to validate them more often with our customers. In those lines, today we published an article that describes some ideas we have on where we could go with the T4 templates we use for code generation, and in particular with the POCO template.

My favorite idea is by far is the “generate once” experience, because I find myself most of the time just using code-gen to create a starting point with me, and when possible, I prefer to extend my own POCO classes (i.e. adding data annotation attributes, new methods and properties) in the same code file, without having to resort to partial classes.

And you, what would you like to see us do with templates in the next release?

Leave a Comment
  • Please add 4 and 5 and type the answer here:
  • Post
  • I'm more of a fan of the template-method and using partial classes to extend the functionality, especially in the beginning of a project when you're still refactoring a lot. What I do miss here is support for WCF attributes, I'd like to be able to pick the exposed members and have the attributes generated. Now I'm exposing DTO's using WCF, which might be a better idea anyway. (Would be nice to generate these as well!)

    What I'd love too see in EF is a bit more extensibility in the creation of POCO entities. Now I'm forced to use property-injection on a OnObjectMaterialized handler. This could be cleaner letting users provide a factory.

  • Hi Robert,

    This is great feedback. I agree that when you have a lot of churn in your model, having templates that keep the classes synchronized makes more sense. I am taking notes on the following:

    1. Option to add DataContract attributes

    2. Option to generate DTOs

    3. On the EF runtime, enable more flexible object mapping (i.e. materialization with factories, field and constructor injection)

    On the last item, if you have time, I would like to get from you some more detail about how this looks like. My understanding is that the factory either must be something that is static or easily created without dependencies, or somehow it must be possible to inject the factory into our materialization code.

    Thanks,

    Diego

Page 1 of 1 (2 items)