Entity Framework Code First–Magic SQL Tool

Having written the plain old  classes (POCO) for my latest Web application, I wasn’t looking forward to creating the corresponding tables in SQL Server. I’m not a database guy really. Just a guy who needs to use databases.

 

Faced with a lot of drudgery, I looked for a shortcut and recalled the Code First capabilities of recent versions of Entity Framework. I know, I’m late to the party but it seems I play with new stuff when it appears as previews and only get my hands dirty when there’s paid work to be done.

 

I turned to the excellent videos on the Get Started with Entity Framework (EF) page. The first video,  Use Code First to define your model in code and then generate a database was all I needed to get me going. Nicely done!

 

The hardest part of the whole operation was discovering where EF had created the SQLExpress database. Perhaps I didn’t refresh SSMS enough times or missed it. Anyway, I realized my code knew where it was even if I didn’t, so a look at the connection string did it:

var db = new SpecificationContext();
System.Diagnostics.Debug.WriteLine(db.Database.Connection.ConnectionString);

Next, I’ve got to investigate the capabilities for automatically updating SQL when my classes change. EF has really become a Magic SQL Tool for guys like me.

2 Comments

Comments have been disabled for this content.