Understanding Active Generation

The Kinetic Framework is meant to be a combination of passive and active code generation. Passive generation is a "one time" generation - a keystroke saver. Active generation means you can regenerate your code at any time. Certain files created by the framework are passive - one time generated files. Most of the "guts" of the generated code is actively generated - they are overwritten whenever you regenerate - and that's a good thing! Imagine the scenario below:

You've been working on your project for a couple of months, and think to yourself, "What if I added coupon codes to the order so customers could get a discount?" Your response: "Sure, I can do that!"

But what you're really thinking is: "Now I have to add a CouponId to the Orders table, and add a Coupons table to the database. Then what am I going to do about my generated code? I've put modifications all over the place, and I don't want to lose them!"

One solution is to regenerate in another folder and merge your changes by hand. But that's error prone, and relies on you remembering all objects that might be touched by your change.

With the Kinetic Framework and the passive/active generation combo, there's another option. Regenerate over the top of what you already have. The framework is designed to respect your changes and ensure you don't lose changes you've made. Some files will get overwritten, but if you follow a few guidelines about where you make modifications, then you should be OK. Before the guidelines, though, here's what gets overwritten when you regenerate:
  1. Any generated.<entity>.cs files: These are generated files, and aren't meant to be modified, so the framework will regenerate these every time. In the change above, this is what would add the CouponId property to your Order object, as well as give you a reference to the Coupon object. The .cs file will not be overwritten if it exists, but if it does not exist, then it will be created. So, in the above example, a Coupon.cs and Generated.Coupon.cs file will be generated.
  2. Framework/.: All files created by the Kinetic Framework and placed in the Framework folder will be overwritten. It's all generic code in there, so it gets overwritten whenever you generate.
  3. Stored Procedures: If you're using stored procedures for your data access, then all of the stored procedures will be overwritten. You'll still have to run them against your database, but the files will be updated. This is important since all of the Order stored procedures would be out of date if you added the CouponId field.

Now, here's what isn't listed here: any solution or project files and your custom entity classes. Those don't get overwritten, so if you add a new entity, such as Coupon, you'll have to include that class in your projects manually - both the .cs file and .generated.cs file. Same thing with the stored procedures - they don’t get automatically included in the database project file. And if you add any custom code to your .cs files, that's also preserved.

End result: you can safely regenerate your entities without fear of losing code if you follow a few guidelines: Don't modify files in the Framework folder and add your custom code to the .cs entity file, leaving the generated.<entity>.cs entity files alone.

Last edited Jul 17, 2008 at 1:47 AM by RossCode, version 5

Comments

No comments yet.