Last post Nov 30, 2006 06:03 AM by tim_mackey
Nov 20, 2006 12:15 PM|tim_mackey|LINK
congratulations on a fantastic piece of software, it's incredible. i wrote a similar asp.net tool 2 years ago without linq and needless to say the resulting code from Blinq is way more elegant!!
i have tried out Blinq with a few reasonably complex databases and to me the most useful thing so far is going to be the static methods and the data classes. the details view forms would be too unfriendly to my novice users without all the client side validation,
auto field focusing, tab-orders etc. if the details view pages could have client side validators for required fields and range validators for numeric fields, that would be the icing on the cake.
my question is really about using Blinq as part of a larger asp.net web application, and how to manage changes to the database and how they affect the blinq code base.
as an example, let's say i have a table called Users, and a field called Password. i want the passwords to be MD5 encrypted so in the Set code block for the Password property in the Users class, i change it like so:
this._Password = EncryptMD5AsHexString(value);
when i add new fields to the database, as invariably happens in the projects i work on, it makes sense to regenerate the blinq classes, and i would lose any customisations embedded in the blinq code. i thought about tackling this problem with inheritance,
implementing a class for each of the Blinq table classes, and overriding any of its properties and methods wherever customisations are needed. but then i realised there are many blinq classes and it would be quite a manual process to create the derived classes
for each table. And it would get messy because all the static methods would use the Blinq/base classes. what i then thought about was to rename the Blinq 'Users' class to 'BlinqUsers' and rename my derived class to 'Users : BlinqUsers' so that it would be
used throughout the static methds, and would include all my customisations. also.. i noticed that the fields in the table classes are private, so derived classes can't access them.. protected fields would be great for an inheritance scenario.
would you have any suggestions here?
Nov 29, 2006 01:23 PM|phuff|LINK
Tim, this is a good question. Blinq doesn't handle changes to schema at all- I usually just recommend to people that they rerun Blinq to another target, then use a diff tool to find the differences and manually merge them. However, this is pretty tedious
if you're making lots of changes to the table schema and plan to keep making those changes. In your case, I think I would handle it differently.
You point out the problems with deriving from the table classes. My suggestion would be to add a new code file to your project that includes partial class declarations for each class and method that you customize, and then you delete the corresponding method
from the StaticMethods or database file that is generated. Your customized method will be compiled directly into the class, and the Blinq-generated web pages and ObjectDataSources will automatically use your new methods. When you change the schema or customize
another method, you can put your file in a safe place, rerun Blinq on your new schema, then copy your file back in. You should get compiler help to point out all the generated overlapping methods that you need to delete from the StaticMethods or database
file. Then you can just delete those generated methods and your customized methods will be used.
Tell me if this works for you or if you find a better way...
Nov 30, 2006 06:03 AM|tim_mackey|LINK
hi polita, partial classes are an excellent idea. I've seen them in action with the new split code-behind model, but never thought to use the new construct to solve problems like this. I tried out your suggestion and it works a treat. The compiler did
complain (thankfully) about the duplicate properties, which will be a great help when regenerating the blinq code.
great idea, thanks!