Reverse Engineer Code First–Jump start for existing Databases

30. May 2011

I know that we have all hit that point where we are going into a project, it has existing database structure and some old ADO.NET hand built data access layer. We think maybe this would be a great place for Entity Framework, and then we find that the business objects are serialized over WCF, or that they are somehow used in a way that makes standard EF cry. This is where we have that internal debate on if our boss will accept a week of writing code just to get code first running, not to solving the problem. In comes the EF Power Toys.

 

Just start up a new project in Visual Studio.

image

With nuget type Install-Package EntityFramework ( this avoids a bug later )

Right click the project and select Entity Framework Reverse Engineer Code first

image 

Punch in your connection information

image

Then watch the bottom left side status messages, it will load schema information, create objects and configuration for them.

You should now have a context, an entities folder, and a mappings folder.

image

This includes every entity in the database and a mapping for every property. It doesn’t leave off properties that could have taken advantage of convention.

You can use this the same way you used a code first context before.

Enjoy.

Data Access, Entity Framework, Productivity, Visual Studio 2010

Visual Studio and Windows authentication from different domains

3. February 2011

I am not sure how many people have tried to connect there personal computer or their work computer to a different domain and use TFS with it but it prompts for user credentials every time. This is a bit annoying especially when you have to punch in the domain every time. There is also the trouble of debugging with a windows authenticated website from the wrong domain. These are fairly common problems for consultants, contractors, and work from home guys who want to use their powerhouse rather than the dinky work laptop. Here is the solution.

 

Create a new short cut and add this to the target

image

C:\Windows\System32\runas.exe /user:<domain>\<user> /netonly "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe"

That is for Visual Studio, You can also do this to hit windows authenticates sql servers from Sql Manager which doesn’t allow you to punch in a different windows user.

C:\Windows\System32\runas.exe /user:<domain>\<user> /netonly "C:\program files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe"

 

These two shortcuts have saved me tons of time in the last several weeks. Feel free to share!

Visual Studio 2010

Turning Off Code Block Highlighting in Visual Studio 2010

1. June 2010

I have been using Visual Studio 2010 for a while now and one of the features that drove me crazy was the block highlighting. I went hunting for a way to turn this off. I found it on a MSDN blog post. I have found I like the feature though just no the default colors. Here is the fix I put in place.

Go to Tools –> Options –> Fonts and Colors:

image

In the Display Items list find Collapsible Region Item:

image

Leave the foreground color the default and change the background to a dark gray. I did it with the custom color selector like so.

image

This makes the regions far more eye candy and less ouch.

image

Enjoy.

Productivity, Visual Studio 2010