Let's say I have two tables in SQL that I want to have an EDMX model generated from (for now, going with automagical generation for everything) using POCO T4 templates. Let's say our two tables are Person (ID, FName, LName)
and Comment (ID, PersonID, CommentText, CommentDate)
with a one-to-many relation between the two (i.e. you can make many comments about one person).
Getting my POCO entities generated from this is trivial and works beautifully. What I don't know how to do now, though, is to add a custom navigation property on my Person
entity that represents the most recent comment for that person (eventually something even more complex than this will ultimately be needed). For now, it's okay that it's read-only but it would be nice to know how to handle an writable property too.
What is the proper way to do this? One thing to consider is that I'm serializing these entities so I will need them to be eager-loaded and persisted in a way that I can push them out to my UI with WCF in the middle (i.e. a custom hand-written property in an extension class that relies on lazy loading is not an option).
I've gotten pretty good at using EF4 for standard stuff, but now that I'm getting into this custom stuff, I'm not entirely sure how to do this in a best practice way.