Connecting to Sql Server from WebMatrix using LINQ and Entity Framework Version 4 - More Wally - Wallace B. McClure
in

MoreWally.com

Giving people what they want, More Wally. This is the technical and personal blog site of
Wallace B. (Wally) McClure.

This Blog

Syndication

News

Please goy buy 3-4 copies of my book on MonoTouch titled "Professional Android Programming with Mono for Android for .NET/C# Developers." They make great gifts all year round. Plus, I get about $.25 when you buy a copy.

Technical Sites

More Wally - Wallace B. McClure

This blog will have all kinds of posts about Wally McClure. In it, there will be tons of .NET and computer programming posts as well as Wally's views on life in general. As you might guess, this site and blog help you get More Wally in your life. What more could anyone want? iPhone, Android, MonoTouch, MonoDroid, Mobile, HTML5, .NET, ADO.NET, ASP.NET, AJAX, jQuery, jQuery Mobile, ASP.NET AJAX, and Windows Azure............follow me on twitter at Wally

Connecting to Sql Server from WebMatrix using LINQ and Entity Framework Version 4

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.

Comments

 

Twitter Trackbacks for Connecting to Sql Server from WebMatrix using LINQ and Entity Framework Version 4 - More Wally - Wallace B. McClure [morewally.com] on Topsy.com said:

Pingback from  Twitter Trackbacks for                 Connecting to Sql Server from WebMatrix using LINQ and Entity Framework Version 4 - More Wally - Wallace B. McClure         [morewally.com]        on Topsy.com

September 6, 2010 8:24 AM
2006 - Wallace B. McClure
Powered by Community Server (Non-Commercial Edition), by Telligent Systems