Understanding Active Generation

Jun 22, 2008 at 3:07 PM
Hi. I'm just getting started using the framework. I'm trying to get a handle on best practices for regeneration after db changes.

My db design is nice and tight (for today, at least).  I've generated my code once, opened and built in in VS, and added it to Subversion. That all went perfectly, and I started building the admin section of my project.  Yesterday I decided to change the table names on all my lookup tables, adding a "ref_" prefix to them, mostly for organizational reasons.   I have not done any custom coding yet, so I could delete or overwrite the entire BLL and database projects. 

Upon regeneration, there seemed to be scattered references to the old table names, and build errors.  The old classes generated for the tables whose names I changed were still in the VS project. Is this just a VS issue?  I've read "Understanding Active generation"  but there are a few details I still need to understand.


In my scenario, should I have

1. deleted all the generated code (I thought not, and did not)
2. In CodeSmith, excluded all the tables except the renamed ones and ones that have a relationship to it?
3. Or just regenerated the whole thing?
4.  In CodeSmith, added "ref_" as a table prefix to remove?
5. Deleted everything in the VS project before regenerating, then going back into Studio and manually including all the new files?

I'm sure it's a combination of 1-5. :) Sorry for the long list of questions. FANTASTIC project, by the way.....

crab



Coordinator
Jun 25, 2008 at 5:16 PM
The solution and project will not get regenerated if it already exists, so there's no worrys there that the will get overwritten. However, that also means that they are not getting modified with the new (or removed) entity .cs class files.

Generally, in my experience, after I've generated a first time and have checked in, I will typically just remove and add the appropriate .cs entity classes to the project after future generations of the entities.
Jun 25, 2008 at 6:29 PM


markjjordan wrote:
The solution and project will not get regenerated if it already exists, so there's no worrys there that the will get overwritten. However, that also means that they are not getting modified with the new (or removed) entity .cs class files.

Generally, in my experience, after I've generated a first time and have checked in, I will typically just remove and add the appropriate .cs entity classes to the project after future generations of the entities.

Mark-
Thanks for the response.  So am I understanding the order of things would be

1.  Delete the .cs entity files from the project (just for the tables you are altering) before regenerating?
2.  Exclude all the other tables in Codesmith except these ones that are changing.....
3.  Re-generate.
4.  Manually re-add the new generated files in VS?

Sorry for being so overly detailed. Thanks for your time. 

crab


 
Coordinator
Jun 25, 2008 at 7:09 PM
Sorry... I don't think I explained myself well.

1. Re-generate.
2. If you renamed any tables,
2a. remove the .cs entity files from the project that have the old name.
2b. add the new-named .cs entity files to the project.
3. If you have any new tables, add the similarly named .cs entity files to the project.
4. If you deleted any tables, remove the similarly named .cs entity files from the project.

All other tables will get regenerated, but you don't have to do anything with those in the project, even if you made table changes.
Jun 25, 2008 at 8:37 PM
Edited Jun 25, 2008 at 8:39 PM


markjjordan wrote:
Sorry... I don't think I explained myself well.

1. Re-generate.
2. If you renamed any tables,
2a. remove the .cs entity files from the project that have the old name.
2b. add the new-named .cs entity files to the project.
3. If you have any new tables, add the similarly named .cs entity files to the project.
4. If you deleted any tables, remove the similarly named .cs entity files from the project.

All other tables will get regenerated, but you don't have to do anything with those in the project, even if you made table changes.


I totally understand. You use the tool every week, I'm sure. It's hard to explain EVERY step to someone who's never used your product.  "Don't they get this, it's SO simple?"

Do the same steps apply if you are changing field names?  In my case, I'm thinking of changing many of the foreign key fields, because it  seems that the framework is happier if you have "id" as the field suffix for primary and foreign keys, is this correct?

Do you have a guidelines doc for happy db conventions when using the framework?
 
Thanks for the reply.

Crab
Coordinator
Jun 26, 2008 at 9:22 PM
The same steps DO apply, even if you are only changing field names or types. The Generated.*.cs entity files will get rewritten, but the *.cs entity files will remain untouched. Just regenerate and you're all set.

Regarding FK fields, we usually recommend having Id appended to the end of the key field. This field will have a respective property on the entity class with the same name, and an additional property will be on the entity class with the Id suffix removed; that property will be the same type as the class/table to which it points.

You might be able to find some information regarding best practice for DB naming conventions in the documentation linked from the home page of the NuSoft Framework. Some instructions regarding generation process can be found at http://www.codeplex.com/nusoftframework/Wiki/View.aspx?title=GettingStarted&referringTitle=Home.

By the way... don't worry about asking questions... There's a learning curve to everything, even eating as ice cream cone (the one that my son wears instead of ingests 8^).
Jun 27, 2008 at 5:14 AM


markjjordan wrote:
The same steps DO apply, even if you are only changing field names or types. The Generated.*.cs entity files will get rewritten, but the *.cs entity files will remain untouched. Just regenerate and you're all set.

Regarding FK fields, we usually recommend having Id appended to the end of the key field. This field will have a respective property on the entity class with the same name, and an additional property will be on the entity class with the Id suffix removed; that property will be the same type as the class/table to which it points.

You might be able to find some information regarding best practice for DB naming conventions in the documentation linked from the home page of the NuSoft Framework. Some instructions regarding generation process can be found at http://www.codeplex.com/nusoftframework/Wiki/View.aspx?title=GettingStarted&referringTitle=Home.

By the way... don't worry about asking questions... There's a learning curve to everything, even eating as ice cream cone (the one that my son wears instead of ingests 8^).

Thanks. So if I have a foreign key "Widget_id"  I'll get that extra property "Widget_".  Excellent.  There's no probklem i deleting the all the generated entity files when I regenerate, correct?

Excellent. My daughter is too fast for me. She figured out in a minute that Daddy wasn't really showing her how to lick the ice cream cone fast enough, but was actually just stealing her treat.



Coordinator
Jun 27, 2008 at 7:00 PM


crab wrote:

Thanks. So if I have a foreign key "Widget_id"  I'll get that extra property "Widget_".  Excellent.  There's no probklem i deleting the all the generated entity files when I regenerate, correct?



Just to clarify... you don't have to manually delete the generated files... when you generate, the generation process will replace/overwrite the existing Generated.*.cs files... I just didn't want you thinking you needed to delete them yourself.



crab wrote:

Excellent. My daughter is too fast for me. She figured out in a minute that Daddy wasn't really showing her how to lick the ice cream cone fast enough, but was actually just stealing her treat.


LOL... the kids really are smarter than we we give them credit for !
Jun 27, 2008 at 11:32 PM


markjjordan wrote:


crab wrote:

Thanks. So if I have a foreign key "Widget_id"  I'll get that extra property "Widget_".  Excellent.  There's no probklem i deleting the all the generated entity files when I regenerate, correct?



Just to clarify... you don't have to manually delete the generated files... when you generate, the generation process will replace/overwrite the existing Generated.*.cs files... I just didn't want you thinking you needed to delete them yourself.



crab wrote:

Excellent. My daughter is too fast for me. She figured out in a minute that Daddy wasn't really showing her how to lick the ice cream cone fast enough, but was actually just stealing her treat.


LOL... the kids really are smarter than we we give them credit for !


Excellent.  I think I started deleting them because when I first renamed tables, the old orphaned classes with the old names were still in the project. I think I am clear now, thanks.  Have a nice weekend.