Friday, April 04, 2008

LINQ and Entity Framework Posts for 4/3/2008+

Note: This post is updated daily or more frequently, depending on the availability of new posts.

John Papa Writes Yet Another Article on LINQ Query Operators

John's Standard Query Operators with LINQ post of April 5, 2008 points to his eponymous article for his "Data Points" column in MSDN Magazine. I thought the market for magazine articles that demo the Standard Query Operators with arrays of numbers and Northwind entities was saturated. Obviously I was wrong.

Added: 4/6/2008

Rumor: Google to Compete Against SimpleDB and SSDS with Bigtable as a Web Service

TechCrunch blogger Mark Hendrickson relies on "a source with knowledge of the launch" to report rumors about Google opening Bigtable to developers in his Source: Google To Launch BigTable As Web Service post of April 4, 2008. Mark says the announcement is scheduled for the week of April 6.

Dave Winer must have had premonitions of the possible event when he wrote a pair of prescient posts that I quote in my Rumor: Google to Compete with SimpleDB and SSDS with Bigtable as a Web Service post of April 5, 2008.

My conclusion: Bigtable's architecture and implementation have more in common with Amazon's Simple DB than either database has with SSDS:

  • Bigtable and SimpleDB aren't relational database management systems (RDBMSs); both resemble multidimensional indexed maps of attribute/value pairs. SSDS attempts to hide the fact that it's an RDBMS.
  • Bigtable and SimpleDB have latency, which results in eventual consistency, although it appears from Table 2 of the Bigtable technical paper that no-latency operation is an option; SSDS has no latency by design.
  • Bigtable values are an "uninterpreted array of bytes" and SimpleDB stores only strings; SSDS has string, number, datetime, binary and boolean datatypes.

Added: 4/5/2008

Updated: 4/6/2008

Randolph Cabral Compares ActiveRecord and Unit of Work Patterns with LINQ to SQL

Randolph's Active Record Vs. Unit of Work post of April 3, 2008 is an essay on the relative merits of and problems with the two design patterns. He cites cardinality issues with updates to associated entities as an Active Record problem. The additional code required to reattach detached objects with LINQ to SQL in Web applications is the major hurdle with the Unit of Work pattern.

Added: 4/5/2008

Julie Lerman Finds Anomaly in the EDM Designer's Update Model from Database Feature

Julie describes in her  EF UpdateModel and naming conflicts post of April 5, 2008 the agonies of creating entities in the EDM Designer, then adding tables for them to a persistence database, and trying to use the Update Model from Database feature to hook the model to the store. In this case, a table and association with identical names blocked the update.

Julie reports that she gave up on the process of updating a simple model from an existing database in her Model first with EDM? post a few hours later.

A message by a member of the ADO.NET team in the ADO.NET Entity Framework and LINQ to Entities (Pre-release) forum, which I no longer can find, mentioned that the team was working on a separate application to create a (presumably SQL Server-only) database from an EDM. This is good news.

However, Julie was attempting to define a CSDL file that can be used with multiple sets of SSDL and MSL files to accommodate different back end databases, so building the database from the model wouldn't appear to solve her problem.

Added: 4/5/2008

Update 4/6/2008: Julie added the following in a comment at the end of the post: "I actually had some success with the model first tests and updated my blog post."

Emad Ibrahim Creates a LINQ to SQL Unit Test with LINQ to Mock (Moq)

Emad's Unit Test Linq to Sql in ASP.Net MVC with Moq post of April 4, 2008 shows how he:

    1. Modified the Moq version of the MvcMockHelpers class from Scott Hanselman and added two more methods to mock an authenticated user
    2. Added a couple of properties to [the] test class (MessageControllerTest) to make it easy ... to access the controller and view engine in all the test methods
    3. Created [a] test method which is going to call a Create method in [the] MessageController and pass it a string.

His post also include links to related resources.

Added: 4/4/2008

Julie Lerman Posts Eight Entity Framework Tutorials on DataDeveloper.net

In addition to writing her book, Julie found time to write eight Entity Framework tutorials. Here's the list with links:

  1. 101 Tutorial:Creating an ADO.NET Entity Framework Entity Data Model
  2. 101 Tutorial: Use an Entity Framework Entity as a WinForms Data Source
  3. 101 Tutorial: ASP.NET DataBinding with the Entity Framework
  4. 101 Tutorials: WPF Databinding with Entity Framework
  5. Many to Many Relationships in the Entity Data Model
  6. Using Stored Procedures for Insert, Update & Delete in an Entity Data Model
  7. Naming conventions in an Entity Data Model: Cleaning up the wizard-generated EDM
  8. Adding items to a LINQ Query of anonymous types - after the fact

Julie says in her Eight Entity Framework Tutorials on DataDeveloper.NET post of April 4, 2008 that the "'101 Tutorials'" are designed to make sure new programmers don't get completely lost."

Added: 4/4/2008

Jesse Liberty: Send LINQ to SQL Data via WCF to a WPF DataGrid in a Silverlight 2.0 Project

The Silverlight.net site's Displaying SQL Database Data in a DataGrid using LINQ and WCF post of April 4, 2008 is a detailed, fully illustrated tutorial for integrating LINQ to SQL, Windows Communication Foundation (WCF) asynchronous service calls, and the new Windows Presentation Foundation (WPF) DataGrid in a Silverlight 2.0 Beta 1 project.

Here are Jesse's links to the source code and a version of the tutorial in PDF.

According to the tutorial's introduction:

The application we’ll build will combine a number of different new skills:

  • Connecting [asynchronously] to a WCF Web Service
  • Using LINQ to query and retrieve data that our Silverlight Application can use
  • Using the DataGrid control to display data

From a strictly Silverlight perspective, building the Web Service and using LINQ are related skills but beyond the scope of these tutorials. That said, we’ll examine how they intersect with Silverlight.

The tutorial is based on material contributed by the Swiss MSDN Team who've produced a 15:00 video segment on it that you can watch at Silverlight 2 Beta1 + WCF + LINQ to SQL = a powerfull combination.

Jesse offers a simpler LINQ to SQL to WPF demo (not Silverlight) in his LINQ To SQL blog post of March 26, 2008.

It should be easy to substitute Entity Framework and LINQ to Entities for LINQ to SQL.

Added: April 4, 2007

Greg Beech Maps LINQ C# Query Expressions into the Underlying LINQ to Objects Method Calls

Greg is a UK developer who's a Development Lead at blinkBox Entertainment currently focusing on the middle tier who's started a "Translating C# 3.0 query syntax for Linq-to-Objects" series. Greg observes:

I haven't found any that go into the gritty details of how the query syntax is translated into the underlying method calls. It's a gap this series aims to fill.

After an explanation of how the compiler handles the translation from query expressions to method calls, he maps the two in a small diagram near the end of each post:

Following are the first three members of the series:

  • Translating C# 3.0 query syntax for Linq-to-Objects, Part 3: Where (4/3/2008)
  • Translating C# 3.0 query syntax for Linq-to-Objects, Part 2: SelectMany (3/29/2008)
  • Translating C# 3.0 query syntax for Linq-to-Objects, Part 1: Select (3/25/2008)

    I'll update this post as Greg posts additional translations.

    Austrailia's Zu Shoe Web Site Uses LINQ to SQL as its Data Access Layer

    Stefan Sedich, an ASP.NET developer for the Vivid Group in Perth, reports in his Our First ASP.NET 3.5 Site Goes Live!! post of April 3, 2008 that Zu Shoe's new site uses the latest technologies:

    • Visual Studio 2008
    • ASP.NET 3.5
    • LINQ to SQL
    • ASP.NET AJAX

    Stefan says:

    All in all this project was great to work on, being able to use .NET 3.5 and Visual Studio 2008 saved us a lot of time, and using LINQ to SQL cut down creating the DAL quite a bit. Of course with all new techs we have had challenges along the way, but still developed it a lot quicker using VS 2008 and .NET 3.5.

    This is the first large commercial site that I've heard uses LINQ to SQL as its data source. Vivid Group has two more ASP.NET 3.5 sites in the works.

    The site has flair; check it out!

    Jeff Currier Demonstrates How to Use SQL Server Data Services' SOAP Client

    Jeff's Interacting with SQL Server Data Services using SOAP post of April 2, 2008 describes SSDS's SOAP client and the generated C# code for the Scope object, which has the following four settings:

    Service Scope - This the scope when a scope object instance is passed to the service without any of the properties set.  This would typically be the case when the intent is to create a new authority object in the service.

    Authority Scope - When just the authority id is specified on the scope object.  This is generally the case when the caller is attempting to create a container, retrieve the set (or a restricted set) of containers from a given authority or finally when attempting to simply retrieve a particular authority instance.

    Container Scope - As you might imagine this scope is established when both the authority and container id properties are set on the scope object.  This scope is typically used when querying within a container for a set of entities (or all entities), creating new entities, or deleting a specific container.

    Entity Scope - Used to narrow the focus of the operation to be performed down to the entity level.  This is typically used when the caller is attempting to update, retrieve or delete a specific entity within the service.

    He then goes on to provide examples of creating a new Authority, Container and Entity, populating the Entity and finally reading its content.

    Following are Jeff's previous posts that cover Java and .NET REST clients:

    SQL Server Data Services Meet Java (Jakarta REST client, 3/19/2008)

    Some SQL Server Data Services Coding Examples (REST client, 3/17/2008)

    The SSDS Team Wants Your Input on SOAP Versus REST Wire Formats

    In the SSDS Team's Jeff has posted some SOAP samples post of April 3, 2008, kellyalt asks:

    We are interested in finding out how many out there will build against REST and how many will build using SOAP.  What are the considerations when you think about using one or the other?  How can we make these interfaces better over time?  These are some of the questions we have in our mind.  Would love to hear from you.

    My reply was 10:1 REST:SOAP because of simplicity and low overhead for public catalog data that doesn't require the WS-* security features afforded by the WSHttpBinding default.

    I'd need to have the REST and SOAP client bits and admission to the beta services to answer the "How can we make these interfaces better over time?" question.

    Overall, I'd say both questions are a bit premature.

    Julie Lerman Explains How to Leverage ObjectQuery Options on a LINQ to Entitities Query

    Julie observes:

    At design time, [a LINQ to Entitities] query is an IQueryable, not an ObjectQuery and doesn't have MergeOptions.

    So you can cast the LINQ to Entities query to an ObjectQuery, set the MergeOption and, as Jeffrey Palermo would say, party on the LINQ to Entities query.

    The whole story is in Julie's ObjectQuery, LINQ to Entities and IQueryable post of April 2, 2008.

    Taking Advantage of Stored Procedures in the Entity Framework

    The Entity Framework (EF) defaults to generating dynamic parameterized Entity SQL (eSQL) statements to populate (hydrate) entities from tables in the underlying relational data store and parameterized data manipulation language (DML) statements to create, update and delete entities and their associated tables.

    Many organizations and individual DBAs prefer or insist on the use of stored procedures rather than dynamic SQL for SELECT, INSERT, UPDATE or DELETE operations. Stored procedures prevent the need to grant users direct access to tables, which could compromise database security. In many cases, the capability to efficiently execute stored procedures instead of dynamic SQL is the principal determining factor in choosing an object/relational mapping (O/RM) tool.

    EF has built-in support for stored procedures but there's no central source of complete, up-to-date documentation and how-to information for using stored procedures with the current Beta 3 version and its Entity Data Model (EDM) Designer CTP 2. The EF Extensions, which add flexibility in the use of custom stored procedures and speed their execution, hasn't been widely used or thoroughly documented. (There were only 181 EF Extension downloads from the MSDN Code Gallery as of 3/31/2008, and Colin Meek only recently published his ADO.Entity Framework: Stored Procedure Customization article on 3/26/2008)

    The following three articles contain detailed instructions with screen captures and code examples for creating entities, changing from dynamic SQL to stored procedures, testing EDMs with stored procedures, as well as minimizing the number of stored procedure calls and improving performance with the EF Extensions:

    Migrating to SQL Server Stored Procedures with the EDM Designer December CTP 2 (March 27, 2008)

    Testing Stored Procedure Replacements for Entity SQL Statements (March 29, 2008)

    Minimize Stored Procedure Calls and Improve Performance with EF Extensions (March 30, 2008)

    Repeated from LINQ and Entity Framework Posts for 3/31/2008+.

  • 3 comments:

    Anonymous said...

    Greg Beech seems similar to what's documented in the C# 3.0 spec document, chapter 7.

    Anonymous said...

    Roger ,

    Just as an FYI, I actually had some success with the model first tests and updated my blog post.

    I'm still laughing at your comment about me finding time to do the tutorials while book writing, while at the same time that you are writing a book you find the time to find, digest and analyze amazing amounts of info on the web and write a gazillion articles. I sometimes wonder if you haven't just cloned yourself! :-)

    julie

    Roger Jennings (--rj) said...

    Julie,

    Your comment certainly is apropos today's NY Times story, "In Web World of 24/7 Stress, Writers Blog Till They Drop" (http://www.nytimes.com/2008/04/06
    /technology/06sweat.html).

    --rj