ASP.NET 1.1 to 2.0 conversion


I'm currently converting a huge 1.1 eCommerce site to 2.0 and its nothing but painful, apart from the stress of dealing with the original site lack of structure, there are some things that just don't work. These are my rumblings.

I first tried converting the 2003 project to a 2005 website and that didn't go too well, after a few hours, I threw that idea out of the window and converted the project into a 2005 web application and it was a success apart from a few minor tweaks.

Here are some other huddles that I had to jump.

  1. ViewState failed to work
    1. I simply set enableEventValidation = false
  2. Warnings about not been XHTML compliant or whatever
    1. I setup the Config entry so that it will conform to legacy
  3. Page_Load was being called twice
    1. Set AutoEventWriteup to false or complete remove OnInit() and InitializeComponent() methods and set AutoEventWriteup = True or use web.config pages to set it globally.

author: Rydal Williams | posted @ Thursday, May 15, 2008 3:03 PM | Feedback (0)

Database Design: [Id] vs [Entity][Id]


Ok, developers/dba's give it to me, I've always designed my database tables with a primary key of "Id", so i.e "Products" table will have a primary key column called "Id". However, I've seen other developers/dba's use "ProductId".

In general, I don't really care, however, since I'm a big fan of ActiveRecord and even before that I've always used "Id". Therefore, referencing my object is as easy as "Product.Id" rather than "Product.ProductId" - duplicate information! but my foreign key usually is "ProductId", so you'll see "OrderItems.ProductId" which makes sense to me. My "OrderItems" table will have a foreign key called "ProductId" back to the "Products.Id" column of the "Products" table.

Which method do you prefer?

author: Rydal Williams | posted @ Tuesday, April 22, 2008 2:01 PM | Feedback (2)

ASP.NET MVC Source Code Now Available


Oh Yes! The ASP.NET source code is now available. Read more at ScottGu's blog. I like open source, no complaints.

Next Steps: Our plans are to release regular drops of the source code going forward.  We'll release source updates every time we do official preview drops.  We will also release interim source refreshes in between the preview drops if you want to be able to track and build the source more frequently.

We are also hoping to ship our unit test suite for ASP.NET MVC in the future as well (right now we use an internal mocking framework within our tests, and we are still doing some work to refactor this dependency before shipping them as well).

Link to ASP.NET MVC Source Code Now Available - ScottGu's Blog

author: Rydal Williams | posted @ Friday, March 21, 2008 1:55 PM | Feedback (0)

Get underlying type from a nullable type


As my forever quest for simple & reusable code keeps growing, I stumble across some bottlenecks once in a while.

Anyway, I have a simple class that is called "PopulateObjectFromFormRequest" and as descriptive as the name is, it does one simple yet helpful task. Given an object as a generic type I.e (user) and a web form as a parameter I.e (aspnetform), it will scan through all the controls of that web form and use reflection on the object and assign values to the object properties that matches controls from within the form.

How does this help me? Well if I my web page that has a registration form and I have a class or struct that needs to be populated with that data, I simply use that class. It prevents me from writing code that fills up an object with data from the web. Therefore, one less task to complete and 5000 less lines of code to write.

What's the problem now? Well, for starters, since I use reflection to determine the type, if the object properties is a nullable type, reflection.GetType() does not equate to typeof(Int32). Therefore, I need to determine if the type of what I'm reflecting is a generic type and nullable, and if it is, I need to drill further down to find the underlying type.

Using SubSonic or DatabaseFly, the datatype for a database column that is of a DateTime and Nullable is DateTime? - whoops, my cool class will fail to determine and assign to the appropriate property or field. Alright, straight to some code and enough talking.

 

#region [ TestUnderlyingTypes ]
internal class NullWeAre
{
    // Create a direct none nullable type variable
    public DateTime TodaysDate;

    // Create a nullable type variable
    public DateTime? DateOfBirth;

    // Create another nullable type
    public Int32? MyAge;

    // Oh, what the heck, through in a string
    public string Name = "Rydal Williams";
}

/// <summary>
/// Method: TestUnderlyingTypes
/// </summary>
public static void TestUnderlyingTypes()
{
    // Test class
    NullWeAre nwa = new NullWeAre();
                           
    // Ok, now lets see how we can get the underlying type
    // Lets perform some reflection on our test class
    //************************************************************************
    System.Reflection.FieldInfo[] fieldsInfos = typeof(NullWeAre).GetFields();
    foreach (System.Reflection.FieldInfo fi in fieldsInfos)
    {
        if (fi.FieldType.IsGenericType
            && fi.FieldType.GetGenericTypeDefinition().Equals(typeof(Nullable<>)))
        {
            // We are dealing with a generic type that is nullable
            Console.WriteLine("Name: {0}, Type: {1}", fi.Name, Nullable.GetUnderlyingType(fi.FieldType));
        }
        else
        {
            // Ok, its just one of those basic data types
            Console.WriteLine("Name: {0}, Type: {1}", fi.Name, fi.FieldType);
        }                
    }
}
#endregion

author: Rydal Williams | posted @ Tuesday, March 11, 2008 11:33 AM | Feedback (1)