Friday, September 16, 2005

Shadows a VB Field with CodeDOM

Follow up on my post for help on sgdotnet, I'll post my findings here as well to share with all.

I've got myself the answer from the book "Applied Microsoft .NET framework programming", a good book to read on the foundamentals of .NET framework, at page 176, says:

CLR Term: Newslot
C# Term: new
VB Term: Shadows
Method should not override a virtual method defined by its base type; the method hides the inherited method. Applies only to virtual methods.

So to say, my code should look like this:

Dim spPreExecuteEvent As New CodeMemberEvent
spPreExecuteEvent.Attributes = MemberAttributes.Public Or MemberAttributes.[New]

However, after the CodeDom compile unit generate the code out, I still didn't find my Shadows keyword on the line. Basically, there's an event from the base class that I want this generated class to shadows on, and upon the generation, the codes appear with warning in visual studio saying that a shadows is recommended there.

Anyway, the code still works, but just doesn't look that nice, it isn't perfect!

Let me know if you have any light on this.


ps: it takes me one whole day to find this thing out, now I know how important search technology is, while Google is still the best, here comes the problem of how to search, what keyword to use, etc. If Google had indexed that book, I would have found it 20 hours ago!

Thursday, September 15, 2005

Microsoft Windows Workflow Foundation

Since the beginning of my company's project, we've in mind to build work flow into the system. We've review a few workflow system vendors and it just doesn't seems to suit us as it would require us much customization work and with limitation.

I believe the market for workflow applications is increasing and it does have a direct impact on the efficiency of a business. That would tells why Microsoft is coming into the stage now.

To be released together with WinFX, the Microsoft Windows Workflow Foundation is now available for preview as well as tryout.


Wednesday, September 14, 2005

Convert a string to an enumerated (enum) value

This problem had been prompting up now and then, and finally I got the solution, which I know definately there is one!

Credits to this site

public enum DataState as Integer
Active = 1
Deleted = 2
Archived = 3

It is very easy and good to use enum, as there's intellisense goes with it and nothing will go wrong. But, how about getting the value mapping back to it's enum so that you got a sure run and error free code?

To get back the enum from the value, this is how you'll go with it:

CType([Enum].Parse(GetType(DataState), "Deleted", True), DataState)

*Need to enclose Enum with "[]" to indicate that you are refering to a class instead of the reserved word "enum" which used to declare an enumeration.


SQL Server 2005 SMO Optimization

While digging the Books Online trying to see what is going on as my SMO program is super slow, Dr.Google lead me to this site.

There's some optimization that you can do to tell the SMO class to retrieve some initial properties of a instance of a SMO class. For convinient, this is a cut-n-paste from the site.

Server svr = new Server();

Database db = svr.Databases["AdventureWorks"];
svr.SetDefaultInitFields(typeof(Table), "CreateDate");
foreach (Table t in db.Tables)
Console.WriteLine(t.Schema + "." + t.Name + " " + t.CreateDate);

By adding this line:
svr.SetDefaultInitFields(typeof(Table), "CreateDate");

It tells the SQL SMO class to retrieve only the specified property (or collection of properties), so that you won't be bloated with lots of SQL statement firing which really slow down the SMO apps.

Well, after all, as the application that I'm doing had to read each table and its columns for its datatypes, thru the Profiler, I can actually see that there's 1 SQL statement being fired for each field in the database, so to say, if I've 120 tables which each tables have more than 8 fields in average, I've to wait for 120*80=960 SQL statements to be fired to get the schema of my database using SMO, that I tell you that took me more than 30 minutes!!

So how? I gave up SMO for this particular app.

What I did finally is to create a Virtual SMO Objects, that means, I create those object but didn't commit it to the database (without firing the .Create()). And using the TSQL querying the system tables, I retrieve all my schema at one go in 1 SQL for each table and fill up the SMO objects. And subsequently, send the SMO objects to my SMO apps. Cool! it works really fast by then.


Monday, September 12, 2005

Generics In-depth

While going thru my code generator for my DAL, I'm looking into optimizing my codes using generics and inheritance so that I can emit a light weight business object with only public variables and associate it with a generic class to make up my DAL.

And while I think generics is just as simple as a "on-the-fly" declaration of type, I'm totally wrong! there's generic method, sub, etc... voila!

And this is the site on, it is really good! a short and nice summary with code samples of the indepth of generics!