Archive for the ‘Software Development’ Category

The Entity Framework, EntityDataSource, OnContextCreated() and OnSavingChanges(…) – ObjectContext Constructor Not Firing OnContextCreated

Sunday, June 7th, 2009
When using the Entity Framework if you want to mess with your entities before they persist to the database one popular way to do it is to hook into SavingChanges from the OnContextCreated method of your Entities ObjectContext like so:

public partial class SomethingEntities
{
partial void OnContextCreated()
{
this.SavingChanges += new EventHandler(OnSavingChanges);
}

public void OnSavingChanges(object sender, System.EventArgs e)
{
//Do stuff
}
}

I was trying to do exactly this but was having a problem. The gosh darn thing wouldn’t fucking fire. In fact, none of the constructors on my Entities ObjectContext were firing. My controls were dancing around all over the place selecting and updating data but nay a constructor to be called.

My EntityDataSource looked like this:

<asp:EntityDataSource ID=”DataSource” ConnectionString=”name=SomethingEntities” DefaultContainerName=”SomethingEntities”
EnableDelete=”True” EnableInsert=”True” EnableUpdate=”True” EntitySetName=”EntityName” runat=”server” />

I was using both the ConnectionString and the DefaultContainerName property as initialization parameters to get the DataSource going. Turns out this wasn’t the right thing to do because when configured this way the DataSource never got my Entities ObjectContext to fire its constructors. I got it to work after some head scratching by changing it to:

<asp:EntityDataSource ID=”DataSource” ContextTypeName=”Namespace.SomethingEntities”
EnableDelete=”True” EnableInsert=”True” EnableUpdate=”True” EntitySetName=”EntityName” runat=”server” />

By using the ContextTypeName property instead of the ConnectionString and DefaultContainerName properties everything seemed to work. A constructor on my Entities ObjectContext was called which in turn called OnContextCreated which hooked up my SavingChanges method which now gets called when it should before changes are persisted to the database.

Problem solved.

The official way to kill and restart Windows Explorer

Friday, June 1st, 2007

It turns out that there’s an official way to restart Windows Explorer. As a developer I have wanted to know how to do this for what seems like 1,000 years, but never bothered to figure it out as you can kill the task from task manager AND re-run a new explorer.exe from the same place.

To shut down officially on Windows 2000 or XP:

  1. In the Start menu choose Shutdown (or Turn Off Computer on Windows XP)
  2. When the Turn Off Computer dialog shows up, press CTRL + SHIFT and hold them down. While holding them down, click cancel on the shutdown dialog. Explorer will quit.
  3. After Explorer quits, hit CTRL + SHIFT+ ESC to bring up the task manager
  4. In Task Manager, choose File->New Task
  5. Type explorer.exe into the box and press enter. All set!

So now I know how to restart Explorer on Windows XP. However, I switched to Vista last year. When you go to Start->Shutdown on Vista, the computer instantly shuts down, giving you no opportunity to do any of the fancy keywork. Any ideas?

Edit 4/29/09: Okay I found the Vista instructions:

  1. Hit the Windows key to bring up the start menu
  2. Press and hold CTRL + SHIFT.  While holding those keys down, right click on an empty area in the start menu (for instance right above the lock icon) and you’ll see a menu that has “Exit Explorer” and “Properties.”
  3. You’re going to want to select “Exit Explorer” in that menu.
  4. After Explorer quits, hit CTRL + SHIFT+ ESC to bring up the task manager
  5. In task manager, select File -> New Task (Run)
  6. Type explorer.exe into the box and press enter. All set!


Action Hero

Monday, May 21st, 2007

I recently got back in touch with a guy I know, and he showed me this cool project he worked on. Here’s sample output from his application that used my face:

Get the Flash Player to see this player.

Looks great! This is the file I uploaded (not even a good snapshot):