Using The NuSoft Framework, Again

posted on 12/19/07 at 09:00:45 pm by Joel Ross

While I'm away on vacation, I figured I'd put up a series of posts on the NuSoft Framework. This is one of those posts.


So you decided to jump on board and use the NuSoft Framework. 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 NuSoft Framework, 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. So when you regenerate, you don't lose what you've already done. 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 NuSoft Framework and placed in the Framework folder will be overwritten. It's all generic code in there, so it gets overwritten whenever you generate - unless there is a *.cs and Generated.*.cs - then only the Generated.*.cs files get overwritten.
  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.

Tags: | |

Categories: Development, Software, RCM Technologies