The World’s Leading Microsoft .NET Magazine
   
 
The .NET Addict's Blog

My Top Tags

                                                           

My RSS Feeds








Latest Diggs - Programming

Internet Blogs - Blog Top Sites

Site Hits

Total: 2,639,104
since: 19 Jan 2005

Getting the Entity Framework working in Orcas Beta 1

posted Mon 23 Apr 07

Despite the fact that I knew that Orcas has no visual designer for the Entity Data Model file trio (CSDL, etc), I wanted to see the Entity Framework crank through some Adventureworks action. It's not a Microsoft beta without hitting the ol' Adventureworks DB!

Much to my chagrin, when I went do to Project -> Add New Item -> ADO.NET Entity Data Model .. the template wasn't there!!! I did some quick panicking, followed by a check on the forums before I did a complete re-install. Turns out that a last-minute bug that crept into the Beta 1 release screwed up that template. This means that the only thing I can do to build an entity model from an existing database is drop to shell (sounds very drill-sergeanty doesn't it? "Drop to shell, soldier, and gimme 20!!") and run EDMGEN.EXE.

If you're following along with the Quickstart, here's the command (ripped from the MSDN forums) to generate the EDM from the School database (students and their associated classes):

edmgen.exe /mode:fullgeneration 
/c:"Data Source=YourServer; Initial Catalog=School; Integrated Security=SSPI"
/project:School /entitycontainer:SchoolEntities /language:CSharp /namespace:SchoolModel

Keep in mind that the /project: parameter is the base name for artifact files, it isn't the name of the .csproj file that you are connecting these files with.

I had to add the following references to my project:

  • System.Data.Entity
  • System.Data.Entity.Design (probabably not necessary, but I added it anyway)
  • System.Runtime.Serialization

Oh, and even worse, the object layer files have a full file reference to the csdl, msl, and ssdl files. In other words, if you move your code to any other directory after you do this, you're screwed. At this point, I was getting pretty upset and frustrated.

**Attention Vista Users** I am running Vista, and I'm running Orcas inside a VMware machine. I had to manually go to Windows Firewall and allow port 1433 to go through (even though the socket was local to begin with) in order to allow the Orcas machine to see the SQL server machine (on my Vista box). This probably won't happen to everyone as my setup is unique, but it's worth keeping in mind.

With the generated files in hand, I added them to my project and checked the Copy Always property on each file. If you don't do this, then when you attempt to hook up to your model at runtime, you will get a big juicy error message.

The next problem is actually connecting to the data source. Another thing that the missing VS template does is add an entry into your App.config file that contains the nested connection string for your model. In short, a model connection string contains a database connection string as well as references to the trio of EDM files. My App.config file looked like this after getting some tips on formatting it from the folks on the MSDN forums:

<configuration>
    <connectionStrings>
        <add name="SchoolEntities"
connectionString="metadata=.\School.csdl|.\School.ssdl|.\School.msl;
provider=System.Data.SqlClient;provider connection string=
&quot;(insert connection string to your DB here)&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>

Finally, after manually generating the trio of entity files, manually adding them to my Orcas solution, choosing the Copy Always option to make sure that my files are copied to the output directory, and manually tweaking the App.config section, I was able to write code that databound the list of students to the combobox the way the "Quick start" tutorial tells you to do it. I'm hoping that MS will release something downloadable that corrects the lack of VS support for the EDM wizard. I know that they don't have a functioning designer, but without the EDM wizard, the Entity Framework is truly painful to get set up.

tags:        

links: digg this    del.icio.us    technorati    reddit




Tag Related Posts

C# 3.0 - Are Object Initializers Evil, Useful, or Both?

Fri 26 Oct 07 10:53 A GMT-05
tags:    

Continuous LINQ - Can I write games with it?

Mon 13 Aug 07 3:09 P GMT-05
tags:        

Silverlight 1.1 Alpha Refresh

Fri 10 Aug 07 2:09 P GMT-05
tags:    

Orcas Beta 2 - might as well be a CTP

Tue 07 Aug 07 1:15 A GMT-05
tags:  

Dynamic, Observable LINQ Views

Tue 31 Jul 07 1:21 A GMT-05
tags:        

Acropolis or Acrapolis?

Thu 05 Jul 07 12:34 P GMT-05
tags:      

My first "Acropolis" Application

Mon 04 Jun 07 1:40 P GMT-05
tags:      

Orcas' Hidden Gem - The managed PNRP stack

Fri 11 May 07 6:45 P GMT-05
tags:        

Orcas EDM Wizard Patched

Fri 27 Apr 07 11:56 A GMT-05
tags:      

Installing Orcas Beta 1 - VMware Style

Mon 23 Apr 07 12:16 P GMT-05

Orcas Beta 1 Released

Fri 20 Apr 07 7:09 P GMT-05

Visual Studio "Orcas" - March CTP is Available

Wed 28 Feb 07 12:28 P GMT-05
tags:            

Objective-C Categories vs C# 3.5 Language Extensions

Mon 26 Feb 07 1:05 P GMT-05
tags:                

ADO.NET Entity Framework Announced Today!

Wed 16 Aug 06 11:08 A GMT-05