September 2007 - Posts

I am going to start spreading the goodness of SubSonic. I think SubSonic is sometimes overlooked for flashy things such as LINQ and Project JASPER. SubSonic is in a transition point (which is apparent when reading Rob Conery's blog), but I think the project still has tons of momentum and is an INVALUABLE resource for ANY .NET developer. If anything, look at the code... it's some good stuff!

 

I'm not going into how to setup SubSonic. That has been covered extensively on the SubSonic website... no need to repeat :)

 

So my first topic will be collections. Yes, Yes, I know this has been covered in other places (such as the SubSonic website) but I am going to go into the ways you can use collections and how they save your life!

 

Yea, about that Collection thing...

One of the cool things about the SubSonic generation is that all the generated objects basically work together. The table objects (as I call them) work with the controllers (most notably the MVC templates that were built). It also has a collection object that is generated. The collection object is basically a Generic Collection (part of System.Collections) but it has been tailored to play nice with SubSonic. I will detail the ways you can load up the table objects into the collection.

 

Use the SubSonic Query!!!

One option is to use the SubSonic Query (very cool tool... I will detail that later) but basically the Query syntax looks like this:

Dim qry as New SubSonic.Query(myDAL.Tables.Products)

qry.AddWhere(myDAL.Products.Columns.orderDate, Comparison.GreaterThan, DateTime.Now())

qry.OrderBy = SubSonic.OrderBy.Asc(myDAL.Products.Columns.orderDate)

Or in C#

Query qry = new SubSonic.Query(Tables.Products);

qry.AddWhere(myDAL.Products.Columns.orderDate, Comparison.GreaterThan, DateTime.Now());

qry.OrderBy = SubSonic.OrderBy.Asc(myDAL.Products.Columns.orderDate);

OK, so the query above goes to the products table, gets the records where the orderDate is greater than the current date, and sorts them by the orderDate ascending. This is sort of a simple example, but the query tool is really cool.

 

You can load up the query into a collection. It's easier doing it that way than pulling it from an IDataReader, trust me :). So this is how you do it:

Dim col as new myDAL.ProductsCollection()

col.LoadAndCloseReader(qry.ExecuteReader())

Or in C#

myDAL.ProductsCollection col = new myDAL.ProductsCollection();

col.LoadAndCloseReader(qry.ExecuteReader());

So now you have a list of Product objects. Now they are at your disposal! You can really do, well, anything with a collection!

 

No, No, No... load it using the Collection

There's another option... loading directly from the collection. Here's the example from above by loading from the collection:

Dim col as myDAL.ProductsCollection = new myDAL.ProductsCollection().Where(myDAL.Products.Columns.orderDate, Comparison.GreaterThan, DateTime.Now()).OrderByAsc(myDAL.Products.Columns.orderDate).Load()

Or in C#

myDAL.ProductsCollection col = new myDAL.ProductsCollection().Where(myDAL.Products.Columns.orderDate, Comparison.GreaterThan, DateTime.Now()).OrderByAsc(myDAL.Products.Columns.orderDate).Load();

So it's basically just the same thing.

 

So which do I choose

I typically load by the collection (basically because it saves me coding time and memory use), but if you are going to do things like Server-Side Paging (which I COMPLETELY recommend and will detail in a later post) you should use the query loading method.

 

Other Cool Things

The Sort method is useful. Instead of loading up the collection with an OrderBy, you can do a sort without the extra SQL think time. In a large system, the number of times you ping your database is important. Anything to save a little memory space.

 

OK, it seems like something you can just look over (since there are other flashy things SubSonic offers), but until you use a SubSonic collection object and use it in your applications, you can't really know how COOL they are. They really help your data access experience work. In the end, that's what any Data Access Tool should do, right?



kick it on DotNetKicks.com

I was just catching up on some RSS feeds and I saw something really cool... the ClubStarterKit open source project was put up on the main ASP.NET site! (http://www.asp.net/downloads/starter-kits/codeplex-club/)

Although I didn't really ask for this to go on there, I think it is appropriate. THANK YOU SO MUCH WHOEVER PUT IT UP! Hopefully we can continue to provide a great community for the ClubStarterKit... and this should help :)

I know exactly what you are thinking: this post is about money. NOPE! It sure isn't :) This post has nothing to do with money and everything to do with JavaScript.

 

The dollar sign has started to pickup use in the JavaScript world lately. In most cases the dollar sign, in JavaScript, represents a class. For jQuery, $ represents the jQuery class as defined in their source code. Here is an example. You can do either of these:

 

jQuery("#result").html("Hello World");

$("#result").html("Hello World");

Both of those do the exact same thing; they both make the element with the results ID have the inner HTML of Hello World. The $ is useful in cutting down your JavaScript code by not having to write jQuery, Prototype, or mootools every 10 seconds.

 

The W3C (WWW Conference) and JavaScript traditionalists doesn't like this one bit! According to them, it isn't "standard compliant". They do have a point... there can be conflicts when using multiple JavaScript libraries. But that can be fixed... just use 1 JavaScript library.

 

So use the dollar sign if you want... or use the actual class name. Either way, your JavaScript framework will just work wonders!

 

NOTE: This was a previous post from my other blog, http://blogs.eagleenvision.net. 

The easiest way to convert from VB to C# or C# to VB is this: learn the language.

I am a BIG VB fan. I've been using VB for nearly 6 years, both VB6 and VB as a part of the .NET framework, and I get arround when it comes to VB. But I recently came across a problem when developing the ClubStarterKit, I needed to convert the whole solution into C# for those who want to use C#. So I got to thinking and I really didn't want to learn C# at the time. I just wanted to convert it and not deal with it any longer.

But here's the problem with that methodology: I started converting the VB solution into C# using my favorite converter (Econ NetVert) and there were errors... many in fact. So I tried to go in an figure out the various problems. I seemed to think there was just 1 solution that would fix all these problems at once and all I had to do was just take the time and make it work. But in my case, that didn't work so well.

So I already knew I was taking this Java class. Turns out that the syntax for Java is pretty similar to that of C#. The only difference I see is that the libraries are VERY different and some of the ways you get user input and what not is very different as well.

I'm learning Java but I am also sort of learning how C# works. It's starting to click and now I can look at a piece of C# code and think, "what does that do" and answer it!

Moral of the story: Learning a language is invaluable when you have to do converting. There really isn't any excuse the C# or VB guys can make to not know both languages. They are both VERY similar and I think converting between one and the other isn't hard as long as you take the time to go ahead and learn the language your are trying to convert it in. REMEMBER: C# and VB both convert to IL!

I think I am going to put in tips for those converting from C# to VB soon. I think that should help Rob Connery and some others figure out what this VB thing is :)

Ahhh... it feels GREAT to have a nice new, blank blog that will serve as my canvas for spreading the Greatness of .NET, ASP.NET, and VB!  To start this little adventure out, I thought I would go ahead and introduce myself.

I'm Zack Owens, as you might have noticed from the top of the blog, and I have 2 big roles in the .NET world. One is my private business, EagleEnvision.NeT, which I will try not to mention on this blog. If you have the remote interest in looking into my business, you can visit our main site or our blog. My second, which will be covered in this blog extensively, is my role as the lead developer for the ClubStarterKit.

Hopefully this will serve as a central place for ClubStarterKit news and tips and hopefully I can drop some hints, patterns, and my own conventions in hopes of helping out the community!

More Posts