I just wanted to post a little fyi on connecting to Sql Server from WebMatrix (Razor, ASP.NET Web Pages) using Entity Framework Version 4. Connecting seems to work perfectly for me. I opened up my web site project in Visual Studio 2010. I then created an ADO.NET Entity Data Model (aka .edmx file). This file went into the App_Code directory of the project. I then wrote the code below in a cshtml file:
@{
ExampleModel.ExampleEntities ee = new ExampleModel.ExampleEntities();
var lst = (from l in ee.Customers select new { l.CustomerID, l.Name });
Response.WriteJson(lst);
}
As you can see, the code is fairly simple. I create the entity connection, create the query, and then pass the query to Response.WriteJson() method. The Response.WriteJson() method causes the query to execute and then serialize the result.
Personal Note: One thing to note is the creation of the object with just the CustomerID and Name values. This is due to a serialization bug in the first beta of WebMatrix. Hopefully, this will get resolved in the next ctp/beta of WebMatrix.