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.

Published Tuesday, June 4, 2013 3:37 PM by Ken Cox [MVP]

Comments

# re: Entity Framework Code First–Magic SQL Tool

Thursday, June 6, 2013 10:12 AM by Rodrigo

You could simply look on the connections string on your config file . That would be a lot easer..

# re: Entity Framework Code First–Magic SQL Tool

Friday, June 21, 2013 5:22 PM by karthick.thoppe

Welcome to EF - Plenty to do!

Leave a Comment

(required) 
(required) 
(optional)
(required)