Dane Morgridge

  Home  |   Contact  |   Syndication    |   Login
  18 Posts | 0 Stories | 13 Comments | 0 Trackbacks

News

I'll be speaking at the CMAP Code Camp on Nov 7.

Twitter












Archives

Post Categories

Thursday, November 19, 2009 #

I just got done with my NotAtPdc Session On "Getting to Know the Entity Framework".  Of course like a good live presentation, my demo broke.  The problem was in the connection string.  When I did the model first development, I named the model something different for some reason and that caused the connection string to be out of sync in the actual application.  Someone had mentioned that was the problem in the chat, but I didn't see it until after the demo was over.  So, in case anyone else happens to run into this error down the road, be sure your connection string in the app that is using your data model is up to date.  And thanks to the person who mentioned that.  (I don't have the chat log in front of me so I don't have your name or I'd give you credit)

Thanks to all that attended my session and you can download the demo code (that actually works) here.


Wednesday, November 18, 2009 #

I am doing my "Getting to the Entity Framework" talk at NotAtPDC this year.  It will be a virtual event via live meeting and will start at 1:30 CST tomorrow, November 19, 2009.  You can get all the details at the NotAtPDC site: http://www.notatpdc.com/Schedule/Detail/27

I will also be doing a quick 15 minute quick start on Entity Framework tomorrow night at the monthly Philly.Net metting with a discussion panel to follow: http://phillydotnet.org/

If you are all interested in checking out what Entity Framework has to offer, both in it's current state and upcoming release, checkout my NotAtPDC session tomorrow. 

I also have several blog posts in the works on some new features coming in Entity Framework 4 and I'll start posting them with in the next few days.


Wednesday, November 11, 2009 #

I had a great time speaking at the CMAP Code Camp last weekend.  Chris Steen and his crew did an awesome job!  Below is the code download and some reference links I mentioned during my presentations.

Code Download

ADO.Net Team Blog: http://blogs.msdn.com/adonet/
Julie Lerman’s Blog: http://thedatafarm.com/blog/
WCF Rest Toolkig: http://www.asp.net/downloads/starter-kits/wcf-rest/


Thursday, November 05, 2009 #

I now have a profile on SpeakerRate.  If you have been to any of my talks to plan to go to any, please do a quick eval and let know what you thought.

http://speakerrate.com/danemorgridge


Thursday, October 29, 2009 #

I was at first a little skeptical about the Entity Framework Model First development in Visual Studio 2010 beta 2.  I was a little worried that the database that was generated wouldn't be something I would want to use in production.  I have used modeling tools before that did a good job and some that didn't.  I decided to take a look at it and was pleasantly suprised at the final generated database.  The process produces a .sql file that you execute on your database that will create the tables and relationships from the model.  Any tables that already exist are dropped and re-created.  If you execute this generated script against a blank compare database, you can use a sql compare tool to get a set of alter scripts to upgrade a dev database. More on that in a later blog post.  Right now I want to show you how you can use Visual Studio 2010 beta 2 as a modeling tool to create a database than you can then use from Visual Studio 2008, effectively giving you Model First development in v1 of Entity Framework.

To start, open up Visual Studio 2010 beta 2 and create a new project, I chose a Console Application, but it really doesn't matter since we are using the project to access an EF data model and no more.  Once you have the project open, add a new file and select "ADO.Net Entity Data Model".

 

 

Select "Empty Model" from the next dialog:

Once you click finish, you will be taken to an empty data model screen:

Now that you have a clean slate, it's time to start adding some entities.  You can either right click in the entity model surface or drag an entity over from the toolbar.  I prefer right-clicking because it gives you a dialog to set some basic options.  You can set those options from the properties window, but to me the dialog is a bit faster.  For this exercise, I'll right click.  You will want to select Add -> Entity:

The following dialog will appear:

I am going to add a "Person" table so I will fill out this dialog as follows:

 

I entered "Person" into the "Entity name" field and the "Entity Set" field was automatically set to "People".  The "Entity Set" is used to set the table name in the physical model and it automatically pluralized.  I changed it to Person to match the "Entity Name".  I have been using singular table names for several years, but you can certainly use plural names if that is your convention as it won't affect your outcome.  I changed the "Property name" field under "Key Property" to "PersonId" because I personally do not like to leave the primary key as simply "Id".  How you do it is up to you, but that is my preference.

The "Key Property" creates the model's primary key.  Note: the "Key Property" is not automatically set as an Identity.   Once you click "Ok", you can set the Identity property.  Click on the "PersonId" in the data model and change the "StoreGeneratedPattern" property to "Identity":

The "Person" entity will get created as the "Person" table when the database gets created.  It's time now to add some properties to get us some columns in the database.  To do this right click on the entity and select Add -> New Scalar Property:

We'll set the name to "FirstName" and have the following:

If you click on the "FirstName" property, you will see the following in the Properties Window:

Note the "Type" is String and "Max Length" is none.  This will create a database table of nvarchar(MAX).  If you set the "Max Length" to "50", the produced column will be a nvarchar(50).  If you want the column type to be a nchar, set "Fixed Length" to true.  The default value for "Fixed Length" is false. 

We will go ahead and create "LastName" and "DateOfBirth" properties.  The "LastName" property will be a string, but the "DateOfBirth" will obviously be a date.  In the property settings for the "DateOfBirth" property, set the "Type" to DateTime: 

Now I will create a new Entity for "Address" with a few standard properties. Our model will not look like this:

 

We need a way to create an relationship between Person and Address so we will create an "Association". To do this right click on Person and select Add -> Association.  It's important to click on "Person" when doing this as it is our starting point and we want the foreign key to be on "Address".

This will bring up a dialog:

We want to have a 1 to many relationship between Person and Address so we will leave these settings.  There are checkboxes for "Navigation Property" on both ends of the association.  When these boxes are checked, the model will include navigation properties to allow you to get a collection of Addresses off of a Person entity by accessing Person.Addressees and Address.Person to get back to the Person entity from an Address. Checking the "Add foreign key properties..." checkbox will include a property for the foreign key to the model.  Clicking "Ok" will create the association and leave our model like this:

If you will notice the Navigation properties on both entities and that Address has a PersonPersonId property.  The property name is comprised of the table name and key property.  Since our key on Person is PersonId, the property is generated as PersonPersonId.  We can simply rename this to just PersonId.

We are now ready to generate a physical database from our conceptual model.  To do this, build the project and then right click on the model surface and select "Generate Database from Model...":

This will give us a dialog:

Since we are just using this to export, you do not need to actually setup a connection here.  You can click "Next".  If you were going to use this model in this project, you would want to make sure you setup a database connection so that it gets linked properly.  Clicking "Next" will give you a preview of the generated sql file:

All you need to do here is click "Finish".  This will produce a confirmation dialog:

You want to click "Yes" to continue.  When finished, you will have a new .sql file in your project:

Create a new database and run this .sql file against it to create your database.  Any time you wish to update the database, you can change the model and generate using the above instructions.  The generation database functions will only generate create scripts and will drop all tables and recreate them.  I would recommend running this against a blank database that can be used for a compare and use a sql compare tool to generate an upgrade script.  Hopefully in the future the database generation tool will be able to do that for you and eliminate this step. 

We have now used Visual Studio 2010 beta 2 as a data modeling tool and we can now take this newly created database back to Visual Studio 2008 to use the currently released version of the Entity Framework.

Open Visual Studio 2008 and create a new Console Application and add a new "ADO.Net Entity Data Model" like we did above in Visual Studio 2010 beta 2.  This time however we will not start with a blank model, but generate it from the database:

Select "Generate From Database" and click "Next":

If you have already added a connection to the Server Explorer in Visual Studio, the connection will be in the drop down.  If you have not, you can create a new connection.  Once you have the proper connection selected click "Next":

This will give the option to select what objects you want in the model.  As you can see the tables to import are identical to the ones we created in the data model.  Click "Finish" and the data model will get created.  You will be taken back to the model surface and as you can see, the model is identical to the one we created using Visual Studio 2010 beta 2.  The only difference is that the Address table doesn't have the PersonId property on it.  This is due to the foreign keys not being directly available on the model in v1.

From here, it's Entity Framework as usual with v1 in Visual Studio 2008 SP1. 

Model First development is a very cool new feature and as you can see, it's one you don't necessarily have to wait for Visual Studio 2010 to be released to use it.  If you use Visual Studio 2010 beta 2 as a data modeling tool, you can use Model First development with v1 of the Entity Framework.  Enjoy!


I am speaking at the Central Maryland Association of .NET Professionals Code Camp on November 7th.  I'll be doing 2 sessions:

Getting to know the Entity Framework
There are quite a few choices when it comes to how to do data access for your .Net application.  With .Net 3.5, Microsoft introduced Linq2Sql which is a powerful ORM solution leveraging Linq technology. The Entity Framework was released with .Net 3.5 SP1 and took the concepts of Linq2Sql to a new level.  The Entity Framework brought additional features over Linq2Sql as well as laying a new foundation for the future of data access in .Net.  In this session we will at a brief history of ORM and then go through a walkthrough of the Entity Framework and flesh out the data access layer of a simple application.  We will look at similarities of Linq2Sql and the Entity Framework as well as some common “gotchas” associated with EF.  We will also take a lap through the new exciting features coming in Entity Framework 4.

Using the Entity Framework behind Web Services
Web services are everywhere and have become a normal part of our lives as developers and most of those services communicate with a database at some point.  Building services in .Net got a lot easier with the introduction of WCF, but using any ORM solution with those services can be a bit tricky, especially if you are doing REST services.  In this session we will look at what it takes to wire web services using the current version of Entity Framework as well as the new features coming in Entity Framework 4.  We will look at several methods of building web services, including WCF, ASMX and REST in both WCF and Asp.net MVC.  You will learn about the common issues with building any service with an ORM framework and how you can leverage the Entity Framework in building them.

For more info check out their site: http://www.cmap-online.org/CodeCamp/Default.aspx

 


Monday, October 26, 2009 #

Last Thursday I presented a talk titled "Examining Linq2Sql & the Entity Framework" at the PhillyXAML meeting.  As promised here is the code download.  There are 2 Visual Studio projects, one for Linq2Sql and one for the Entity Framework as well as a sql file to create the database used in both.  Zip link is below:

ExaminingLinq2SqlAndEntityFramework.zip (466.46 kb)

Here are some links I mentioned in the talk:

WCF REST Starter Kit - A must see if you are doing any REST services with WCF
Julie Lerman's Blog - She has a ton of good info on the Entity Framework


Saturday, September 26, 2009 #

I have often heard programmers refer to them selves as either ninjas, pirates or monkeys.  I have also seen a lot of talk about how ninjas are better than pirates, especially on twitter on talk like a pirate day.  There are shirts at ThinkGeek about Killer Coding Ninja Monkeys which I find to be cool and very interesting all at the same time. 

Ninjas are assassins and they kill stuff.  They are generally pretty quiet and if they do their job right no one really even knows they are there.  Pirates tend to be a bit crazy.  I'm talking about the Jack Sparrow type pirates and not the Somalian ones.  They kill stuff too, but are pretty rowdy, don't have a problem using rusty swords or cannon balls to get the job done.  Monkeys... well they eat bananas and throw poop. 

When you look at them from a programming perspective, I see the ninja as the one who can gracefully get any bit of code written while killing bugs before people even know they exist.  They are the ones that you don't normally see much because they are busy writing code and you almost take their existance for granted, as long as nothing is broken.  When something does break, they attack the problem and fix it without it even knowing the guy was coming. 

Pirates are the louder programmers, you know, the ones who stand next to your cube and talk about the movie they saw last night or brag about the huge plasma tv they just bought.  They do get stuff done, albeit maybe a little messy.  Seriously, have you ever seen anything that got hit by a cannon ball before?  Their approach may not be the best, but they usually get the job done.

Then you have monkeys.  Hopefully you don't have any programmers at work that throw poop...  Tootsie rolls maybe.  I have heard several people consider themselves "Code Monkeys" which I can find to be a derogatory term at times.  You have probably heard the phrase "a monkey could do it".  That means it's easy and meaningless and that you might be better off hiring some chimps.  There are some jobs that dictate that kind of work and, for all intents and purposes, you are really nothing more than a monkey writing code.

I think, personally, that there is a bit of all three in most of us.  A lot of programmers will code like a ninja, goof off like a pirate and frequently get treated like a monkey.  You have the skill to swiftly take care of any problem in your path.  When your code is compiling or you have some down time, you might act a little crazy and get rowdy. And I don't know a single programmer that hasn't, at some point, been treated like he was nothing more than a monkey writing code.

I think that every programmer should take a look inward and embrace their inner ninja|pirate|monkey and if you team it up right, you might be able to have someone blow the wall apart with a cannon ball so the ninja can sneak in and take out the guard so the monkey can throw some poop at the real problem.  I'll let you decide who or what the real problem is...


Friday, September 18, 2009 #

If you are doing REST webservices in .Net, you may have tried WCF to do this.  This can be a bit tricky to setup and get working.  Once it is working, it works well, but getting it going can be fun.  I was working on a new project last night where I needed some REST services and I had thought about doing it Java or Python to get a quick version up and running so I could test my client, but I really wanted to do it in WCF so I spent a little time searching and came across the WCF REST Starter Kit.  This has to be the coolest out of band project I have seen since the ASP.Net Ajax toolkit.  If you are doing REST, it is the best/easiest way to get started.  It creates a clean web application with a REST service that just works!  I say again, It Just Works! 

Once I got the REST service working, I needed to hook in some basic http authentication and it didn't take me long to come to Pablo Cibraro's blog.  He has a series of posts on how to setup http auth with ASP.Net that authenticates against a custom (non-AD) membership provider.  Very cool stuff.  Using his posts, I was able to get the basic auth setup very quickly.

If you are planning to do REST with WCF, here are some good resources to help get you going:

WCF REST Starter Kit
Pablo Cibraro's Blog, custom authentication post
Stephen Forte's Blog

Another awesome resource is Dan Rigsby's blog.  He has a lot of good WCF stuff there.


Wednesday, September 16, 2009 #

I'm speaking at the next Philly Code Camp on Oct 17, 2009.  I'll be presenting in the Alt.Net track on "Crossing the Chasm: Develop, Build, and Deploy .NET Apps Cross-Platform with Mono".  I will cover building .Net apps on Mac and Linux and even touch on MonoTouch, the .Net framework sdk for the iPhone.  Registration will be opening soon, I would love you see you there.

For more information go to the Philly Code Camp Website: http://codecamp.phillydotnet.org/2009-2/default.aspx