Daily Archives: January 19, 2010

Some Visual Studio tips I picked up recently

Earlier this month, Rob Hale presented at the Vermont.NET User Group on what he learned at PDC. There was a lot of great information; but oddly, two tiny little Visual Studio features stood out for me.

One is not even new to VS2010.

Recent Project Tricks on Start Page

There are a zillion new productivity features in VS2010 but this one had escaped me (and surely a few thousand others as well).

In VS2008, I modified my startup settings so that I didn’t have to look at the start page. I will absolutely leave it in place in VS2010.

I really like the way the recent projects are displayed on the VS2010 Start Page, but did you know that you can control how those projects are displayed?

You can PIN projects that you want to stay on the start page and unpin them when they are  no longer necessary.

Just by hovering your mouse over to the space to the left of the project, the pin will appear and you can click it to pin the project down.

 

 

image

 

image

You can also remove projects from the list and open their containing folder right from the start page.

image

Block Selection in Code Editor

Another IDE trick Rob showed us is not even new to VS2010 – block selection – which can be used vertically.

If you hold down the alt key while dragging your mouse across and down, you can highlight text vertically.

Rob pointed out a useful example.

Say you have some repeated code, such as instantiating some objects with values, but you need to change something

Here, I have used ALT and dragged down in front of the F of FirstName. Notice the faint blue line. I could drag across and highlight text in a column if I wanted also.

image

Now I start typing to add in the ModifiedDate property.

image

Whatever I type is mirrored in all of the rows of my selected block. Really cool.

Recent Project Templates

Matt Kleinwaks brought this one up on a listserv today and I was again, surprised. This one is new to VS2010 but I had overlooked it.

Visual Studio remembers which project templates you have used recently and make it easy for you to select them.

I’ve never paid attention to the Recent Templates section much less ever clicked on it an opened it up. Matt wrote up a quick blog post about it this morning, so I’ll just point you over there if you need your eyes opened to this little feature: Avoid Template Overload in VS2010

So many tips & tricks

I have a few of the wonderful VS Tips & Tricks books written by various authors. Maybe I should place them on the kitchen counter and make a habit learn new tricks while I’m eating breakfast or lunch.

Leveraging VS2010’s Entity Data Model Designer for .NET 3.5 Projects

One of the benefits of Visual Studio’s multi-targeting is that if you are still stuck using the .NET 3.5 version of Entity Framework and are unable to move to EF4 (so sad), you can still get the new designer goodies for a .NET 3.5 project.  Remember that the designer is a VS2010 feature, not a .NET 4.0 feature.

Be sure to select .NET 3.5 when you create your project:

image

When you add the model, you’ll notice that the foreign key checkbox is disabled. FK support is not only an EF4 designer feature but it is dependent on .NET 4. But you can still get the much needed pluralization support.

 image

Once the model is created, you can take advantage of new designer features such as the complex type support. Complex tyeps existed in .NET 3.5 but the designer did not support them making it painful to take advantage of them.

image

image

Here is that complex type in an entity that was retrieved from the database.

image

Model First works too:

image

Not every new designer feature will work with an older model though.

T4 code generation won’t. You can select “Create Code Generation Item” from the context menu, but no templates will be available.

image

EF 3.5 uses a different type of code generation.

Function Import will NOT provide the nifty EF4 support for mapping stored procedure results to Complex Types:

image

Without the Foreign Key support, the model will use what’s called “Independent Associations” in other words, the same type of associations that we were limited to in .NET 3.5 where the association was dependent on the mappings.

Even though the designer has a referential constraint in the properties window, you can’t build it with this model because the foreign key is not available.

image

(With an EF4 model, you can use either Independent Associations or Foreign Key Associations.)

So if you are stuck building EF v3.5 apps (oh please please move to EF4, life will be SO much happier!), you can still get a lot of benefit from using VS2010’s designer.