|
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:
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=
"(insert connection string to your DB here)"" 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.