views:

539

answers:

1

I am using Subsonic 3 ActiveRecord approach and was wondering what was most efficient in terms of posting data. Here are the 2 scenarios:

i)

public ActionResult Edit(Person PostedItem)
{
        Person p = new Person(PostedItem.ID);
        p.Name = PostedItem.Name;
        p.Update();
}

ii)

public ActionResult Edit(FormCollection PostedItem)
{
        Person p = new Person(PostedItem["ID"]);
        p.Name = PostedItem["Name"];
        p.Update();
}

I would imagine the FormCollection is more efficient as the modelbinding reflection process does not need to occur however its nicer to have something strongly typed.

Is there an alternative approach? Is there anything else that can be put in the Edit parameters that pass the posted data?

Thanks

+2  A: 

I think that reflection performance is completely unimportant here. Heck, it might even be faster than string indexing -- I've never bothered to measure. Whatever the actual cost is, it will almost certainly be eclipsed by the cost of saving the changes to the DB. Also, edits (as opposed to page loads) don't happen so often that a few milliseconds will load your server.

The first rule of real optimization is to profile your app and only optimize the parts which are actually slow!

Craig Stuntz