Calculated Fields

Feb 28, 2012 at 10:34 PM
Edited Feb 29, 2012 at 2:31 AM

this project is so cool!!

I have been going through the code and I see we can also modify your nice EF Code First POCO generator classes/templates to generate Ria Services Metadata POCO with tons of Data Anotations validation.
I have a question about adding the following feature

1- After the Schema is read, put it into some kind of container to be able to add parameters and properties to each table, for example Calculated Fields, if the table has “FirstName” and “LastName”, we could  add a calculated field called “FullName” = FirstName  + " " + LastName. “FullName” does not need to exist on the database, just be part of the POCO Model.

Adding this feature (load all fields into a container allowing the user to add fields with formulas for each Table on the Schema) , will be great.

Also, If we have and Invoice , for example , we could add some type of mechanism to allow the selection of child tables for each parent (Invoice Details for example)  and do stuff wit it.

Any hints or ideas  on how to achieve this ?


Feb 29, 2012 at 6:26 AM

My plan is to have a "CodeModel" with a list of Entities, each with Properties.

Each property has a name, a .Net type and is linked to the corresponding column. If there is no link, the property is (in EF CodeFirst terms) [NotMapped]

The schema can be projected into a CodeModel (simply read the Tables/Columns each with there .NetName and .DataType.NetDataTypeCSharpName). Foreign keys can also be projected in. The CodeModel can be edited in code and fed into the CodeWriter.

I was just going to write automatic properties for these, but to support your scenario I could have a code block on the property which we write in. We could even support methods this way...


Not sure what you mean with the child tables selection. If you have a foreign key relationship between Invoice and InvoiceDetails, then Invoice will have a collection of InvoiceDetails. InvoiceDetails will have a Invoice property pointing to the parent. In NHibernate and CodeFirst, which are the main scenarios I support, you simply use the ISession CreateFilter / DbContext Entry().Query to apply filtering.