Tuesday, June 17, 2008

LINQ and Entity Framework Posts for 6/16/2008+

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

Frans Bouma Starts New Features in LINQ to LLBLGen Pro Series

Linq to LLBLGen Pro: feature highlights, part 1 of June 17, 2008 is the first of a series that Frans promises will “sum up some of the characteristic features of Linq to LLBLGen Pro, so you don't have to wade through the 15 articles I wrote about writing Linq to LLBLGen Pro.”

Frans emphasizes that “Linq to LLBLGen Pro is a full implementation of Linq” and delivers a set of questions about the specific LINQ operators and related features a LINQ-enabled O/RM tool should support. These question could well serve as the start of a criteria list for a .NET O/RM comparison table.

Wading through the 15 articles Frans wrote while writing the LINQ implementation is an exceptional opportunity to learn more about implementing LINQ in a .NET O/RM. Here they are:

Surprising Lack of Activity in SQL Server Data Services Forum

My All’s Quiet on the SQL Server Data Services Front post of June 17, 2008 starts with:

I'm surprised at the current lack of relevant threads in the SQL Server Data Services (SSDS) - Getting Started forum, which appears to have commenced operations on May 19, 2008 but garnered its first message on May 29.

And goes on to offer some potential reasons for the apparent lack of interest.

Update 6/17/2008 1530 PDT: SSDS evangelist David Robinson contests my conclusions and says in his Peace & Quiet? post of June 17, 2008:

[W]e are working with companies of all shapes and sizes, from some of the worlds largest banks to small start-ups, customers covering almost every industry imaginable.

He also added this comment to my post.

Added: 6/17/2008

ADO.NET Sync Services Team Posts How-To for Bi-Directional Synchronization

The Extending Visual Studio 2008 SP1 Sync Designer to Support Bi-Directional Synchronization post contains a link to recently-released documentation for enabling bi-directional sync between SQL Server Compact and SQL Server 20085+.

As you can see in this excerpt from the SP1 docs, the amount of code to enable bidi sync for a simple Northwind Customers table isn’t insignificant.

Added: 6/17/2008

LINQ and Related Sessions at CodeStock 2008 In Knoxville, TN

The CodeStock 2008 conference to be held August 9, 2008 at Pellissippi State Technical Community College in Knoxville, TN offer the following LINQ-Related sessions:

The one-day conference has six simultaneous sessions.

I’m surprised that no one’s covering Entity Framework and ADO.NET Data Services.

Thanks to Wally McClure for the heads-up on June 16, 2008.

CIO Magazine Posts Article on LINQ and TechFunk Copies It Verbatim

CIO Magazine’s Five Things the Boss Should Know About Microsoft's LINQ article of June 16, 2008 by John Paul Mueller is a semi-technical paean to the benefits of LINQ that emphasizes database queries.

What makes the story more interesting is the TechFunk blog’s word-for-word reproduction of the article in their Five Things the Boss Should Know About Microsoft's LINQ post of the same date. TechFunk provides no attribution whatsoever to CIO Magazine, for whatever that’s worth.

I’ve never seen a more flagrant case of plagiarism and copyright infringement by a technically-oriented blog.

Update 6/17/2008: Don’t get me wrong; I’m not a copyright bigot. This blog’s content is licensed under the Creative Commons Attribution 3.0 License.

AP is nuts for charging $12.50 for the fifth word quoted from their newsfeed and barring any excerpts if they find “Your use of the licensed Content to be offensive and/or damaging to Publisher’s reputation," as reported in TechDirt’s Associated Press: Fair Use Limits You To Four Words; Five Words Costs $12.50 post of June 17, 2008.

Steve Naughton Starts Database-Based Permissions Series for ASP.NET Dynamic Data

Immediately after finishing his seven-part A DynamicData Attribute Based Permission Solution using User Roles series, Steve has embarked on DynamicData: Database Based Permissions - Part 1, which moves the ASPNETDB users and roles tables on which the permissions were set. The next episode will be “Creating the user interface for setting the database based attributes.”

David Ebbo Explains ASP.NET Dynamic Data’s Associated MetaData Class and Its Future

Dynamic Data uses metadata attributes applied to entity classes or their properties to specify complex data types, format data, add validation rules, and other custom entity and property features. In his Dynamic Data and the Associated Metadata Class post of June 16, 2008, David explains how attribute-based metadata works today and how it might change in future versions.

Marcelo Lopez Ruiz Explains the Importance of ADO.NET Data Services’ InitializeService() Method

Marcelo notes in his So Special - InitializeService in ADO.NET Data Services post of June 16, 2008 that service initialization is a one-time process controlled by an internal static dictionary whose lifetime is that of the AppDomain. Marcelo recommends invoking the InitializeService() method explicitly to set the service’s configuration and error handling options.

Marcelo says his next post will “focus on the configuration object.”

Update 6/17/2008: Marcelo’s Why is my ADO.NET Data Service empty? post answers the question with:

The service configuration allows you to specify what access you want clients to have (by default) on entity sets. You may further restrict access through interceptors, but you can never grant more access than that specified on the configuration. …

By default, the service is completely locked down - all the entity sets have no access rights granted for them, and so the data service looks empty - you can't access any resource at all. That's why folks are sometimes baffled when "everything works", but nothing is accessible. You should implement the InitializeService method and start granting access on a per-entity-set basis, and then you're ready to go.

Craig Shoemaker Shows How to “create wildly different layouts and easily add third-party controls to your Dynamic Data websites”

His Rockstar Dynamic Data Customizations post of June 16, 2008 has links to the following five podcasts:

He also has an Introduction to Dynamic Data screencast and podcast that are subtitled “Get started with ASP.NET Dynamic Data with some practical advice.”

Craig is a “new-media evangelist” for Infragistics, so expect to see some third party controls in the preceding examples.

Serena Yeoh Updates Layered .NET Architecture Sample to .NET 3.5 and LINQ to SQL

Serena (a.k.a. Firedancer), who works for Microsoft Consulting Services, has updated her Layered Architecture Sample for .NET project on CodePlex by replacing the Data Access Application Block (DAAB) with LINQ to SQL, changing Business Entities to LINQ to SQL Entities, and implementing .NET 3.5 Workflow services. She says:

Layered Architecture Sample is created to demonstrate how we can apply some of these .NET technologies with the Layered Architecture design pattern. It is a simple example that illustrates the factoring of responsibilities and separation of concerns into multiple layers in an enterprise application. As the name implies, the main focus of the sample is "How to code the layers?" and not the actual functionality of the chosen Expense application. The Expense Business Process Flow was chosen simply because it is widely used and easiest to understand.

Serena provides additional insight to the project in her Layered.Architecture.Sample.for.NET.3.5 post of May 28, 2008. (Notice the emphasis on layered, not tiered.)

Thanks to Patrick Yong’s Layered Architecture Sample for .NET post of June 16, 2008 for the heads-up.

Off-Topic: Does Google Gears Deserve its Recent Notoriety?

MIX’s Joshua Allen tries to brake the Google Gears hype train stoked by Dare Obasanjo with his Google Gears as the Next Flash post and TechCrunch’s Nik Cubrilovic with Get Ready For A New Platform War. Google Gears Drives Straight At Microsoft’s Profits in his Gears a Profit-Killer? post of June 16, 2008.

Google Gears languished in obscurity until the “demo of a gears-enabled MySpace mail client prototype, shown at Google I/O” by two ex-Microsoft folks, one of whom was Mark Lucovsky, the architect of Hailstorm.

My Google Gears Piques New Interest in Data Synchronization post of June 1, 2007 covered the initial announcement of Google Gears at their 2007 Developer day. It also notes that Scott Hanselman almost swooned over Google Gears in his Google Gears - Maybe all Rich Internet Applications needed was Local Storage and an Offline Mode of May 30, 2008. Scott said, inter alia:

This is a huge move and is quite brilliant. In one seemingly innocuous move (and one tiny 700k (yes, 700K) download) Google is well positioned to get Google Docs, including Writely, Spreadsheet and Presentation, along with who knows what else, enabled for offline use. And the whole thing is Open Sourced via the New BSD License.

A year later, Google Gears implementations are few and far between.

Off-Topic: Migrating from Access/Jet to SQL Server Panel Discussion from Tech*Ed 2008

According to panelist Mary Chipman, “rumors of Access’s death have been greatly exaggerated.” The panel answers the question: Are we there yet? Successfully navigating the bumpy road from Access to SQL Server.

Of course the current Microsoft party line is to substitute SharePoint lists for Access/Jet databases.

All’s Quiet on the SQL Server Data Services Front

I'm surprised at the current lack of relevant threads in the SQL Server Data Services (SSDS) - Getting Started forum, which appears to have commenced operations on May 19, 2008 but garnered its first message on May 29.

There are messages that refer to admitting new beta users "in waves," but only 10 of the 36 threads in this forum so far are about SSDS. What's more, there were 0 feedback responses when I wrote this post.

Part of the problem might be lack of publicity for the forum. I mentioned the forum in LINQ and Entity Framework Posts for 5/29/2008+, but it doesn't have a link on Microsoft’s SSDS home page nor do I recall any mention of the forum in the SSDS blog or blogs by SSDS team members.

An alternative theory is that there is less interest in generic “database services in the cloud” than Microsoft expected when it launched SSDS. Part of the problem, in my opinion, is the contrast between the initial SSDS offering’s somewhat nebulous architecture—schemaless authorities, containers and entities with five primitive data types offering neither foreign keys nor joins—and the schema-based design of traditional relational databases.

Microsoft appears to be addressing the architectural issues by promising joins, which would imply support for foreign keys, but the team is sending mixed signals about the chances for schemas on the new features list.

I believe that SSDS would have gained greater initial mindshare in the fledgling cloud database market if they had simply exposed an ADO.NET Data Services (Astoria) front end and provided users with out-of-band access for executing T-SQL Data Definition Language (DDL) batches and a variation on BCP or Astoria batching for bulk uploads. An advantage of emulating Astoria is that users wouldn’t be locked into SSDS. In addition, the SSDS folks could support an automated port from on-premises Astoria to cloud-based SSDS.

Note: Perhaps SSDS users are posting their questions in Microsoft Connect’s SSDS Connection. Only one of my five bug reports in Microsoft Connect Feedback was answered; that one was posted on 4/15/2008 and answered on 6/16/2008. Feedback is private in the SSDS section, so I don’t know whether others have received more timely responses.

Update 6/17/2008 1300 PDT: Another contributor to developer ennui in the SSDS department is lack of the promised SSDS client. From the “Application Agility” topic of SSDS home page:

  • A rich client library in C# or VB providing LINQ query support will be available.

Here’s the response to a “Will there be any tool to help us build an application against SSDS?” forum question:

The answer is absolutely YES, but we can't really comment on a timeframe as of yet.

Update 6/17/2008 1530 PDT: SSDS evangelist David Robinson contests my conclusions and says in his Peace & Quiet? post of June 17, 2008:

[W]e are working with companies of all shapes and sizes, from some of the worlds largest banks to small start-ups, customers covering almost every industry imaginable.

He also added this comment to my post.

Dave promises:

Over the next day or so, I plan on starting a new series of blog postings on SSDS Best Practices. I will start with the content from my TechEd presentation and I will continue to add to it as we add more and more features to SSDS.

A feature I’d like to see added is role-based security with controlled public access.

Backstory: IBM’s November 15, 2007 announcement of its Blue Cloud distributed computing initiative generated 754,000 hits for the past year with a Google search on ibm “blue cloud”. Only 39,300 hits occurred in the past three months, which indicates quickly diminishing interest as Big Blue failed to expose its purported service to actual users.

A possible reason for the reduced press coverage is the company’s schizophrenic view of cloud computing, as reported by RedMonk’s Michael Coté in the “IBM and cloud computing” topic of his May 27, 2008 IBM Tivoli Pulse: Tivoli product updates and cloud confusion article for SearchDataCenter.com. Meanwhile, Amazon and Google maintain their headlock on what cloud mindshare there exists among developers.

What’s your take on SSDS’s status?

Monday, June 16, 2008

LINQ and Entity Framework Posts for 6/12/2008+

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

Updated 6/15/2006 and 6/16/2006.

Illustrated Walkthroughs for Creating Web Apps and Web Sites with ASP.NET Dynamic Data

ASP.NET Dynamic Data projects come in two flavors:

  1. Dynamic Web applications or file-based Web sites that use either the Entity Data Model or LINQ to SQL as their data model.
  2. Static (Custom) Web sites that you create with the Dynamic Data Wizard. These sites currently are limited to LINQ to SQL only as their data source.

My forthcoming “Scaffold Web Apps with ASP.NET Dynamic Data” article for Visual Studio Magazine includes walkthroughs for creating the preceding two project types with Northwind as the backing database.

Publishing limitations precluded step-by-step screen captures, so I created two posts to illustrate the process:

  1. Dynamic Web application: ASP.NET Dynamic Data: Generate a Dynamic Administrative Web App from an Entity Data Model in Less than Five Minutes
  2. Static Wizard-generated Web site: ASP.NET Dynamic Data: Scaffold a Custom Administrative Web Site with a LINQ to SQL Data Model in Less than Five Minutes

An obvious drawback to the Wizard-generated site is lack of DynamicFilter dropdowns for filtering on EntityReference (foreign key) values.

Added: 6/15/2008

David Ebbo Explains ASP.NET Dynamic Data’s Handling of Foreign Keys in Scaffolded Dynamic Controls

David discusses how ASP.NET Dynamic Data displays EntityReferences from foreign keys in his Understanding foreign keys and relationship columns in Dynamic Data post of June 13, 2008. The discussion applies to grids and details views with Entity Data Model and LINQ to SQL as data models.

As David mentions, foreign key values (usually integers) appear when you use LINQ to SQL as the data model. The Entity Data Model replaces foreign key with Navigation Properties (EntityRefs.)

One reason folks become confused about foreign-key handling is that Dynamic Data requires LINQ-enabled data sources, such as the LinqDataSource and EntityDataSource, which implies using object terminology (e.g., classes, types, associations, entities, entity sets, entity references, etc.). This usage conflicts with relational terminology (primary and foreign keys.) The help files and blog posts have a tendency to favor the relational (data) dialect.

Mike Taulty Tackles Implementing IUpdatable() for LINQ to SQL DataContexts Backing ADO.NET Data Services

Mike’s ADO.NET Data Services - IUpdatable on LINQ to SQL post of June 14, 2008 discusses four possibilities for creating an updatable LINQ to SQL data model for use with ADO.NET Data Services. His final choice (#4) requires the developer to derive from <T> manually, as is the case with ADO.NET Data Service’s Web services.

Note: The Data Programmability group’s failure to update LINQ to SQL with an IUpdatable implementation is one more nail in the product’s coffin. (I neglected to mention this issue in my Is the ADO.NET Team Abandoning LINQ to SQL? post of May 23, 2008.

asp.netPRO Magazine’s June Issue Carries an ASP.NET Dynamic Data Article That’s Ina Finally Accessible Online

The aspnetNOW nesletter for June 12, 2008 says the “ASP.NET team's own Marcin Dobosz and Scott Hunter provide an introduction to Dynamic Data,” and “the June issue of asp.netPRO is now available as a FREE PDF.“

The problem is that it isn’t available. The asp.netPRO folks forgot to renew their NetworkSolutions domain registration, which expired on June 8, 2008.

When (and if) they get their domain registration problems straightened out, I’ll add a new blurb.

“An Introduction to ASP.NET Dynamic Data: Rapidly Create Rich Data-Bound Sites” is now accessible at http://www.aspnetpro.com/PDF/Issues/aspJUNE2008.pdf.

Bart De Smet Posts First Episode of His LINQ to MSI Implementation

Bart says in his LINQ to MSI - Part 1 – Interop post of June 13, 2008:

So, in this post of this series we'll take a look at some very simple MSI interop, giving us a basic data provider for MSI databases, mirrored after the typical structure of .NET data providers like System.Data.SqlClient.

And then goes on to discuss:

  • Interop signatures
  • Respecting well-known patterns
    • The connection
    • The command
    • The data reader
  • Sample

He adds a postscript to the preceding post in LINQ to MSI - Part 1 bis - Interop with SafeHandles of June 14, 2008.

Mike Taulty Diagnoses DataSvcUtil’s Namespace Errors When Creating Web Service Proxies

Mike solve issues with “The 'Namespace' attribute is invalid - The value ''  is invalid according to its datatype 'http://schemas.microsoft.com/ado/2006/04/’” errors in his ADO.NET Data Services and LINQ to SQL - Errors Generating Proxy Code with DataSvcUtil.exe post of April 13, 2008.

Matthieu Mezil Illustrates Use of AsEnumerable() That Mystifies Me

Matthieu’s AsEnumerable: not only to use unsupported methods post of June 13, 2008 discusses the differences in the results of a pair of complex LINQ to SQL queries whose primary distinction is use of AsEnumerable() to solve a problem obtaining Northwind Order instances with OrderDates in 1998 having French customers together with their Customer instances.

So I wrote the following relatively simple query that returned what I thought Matthieu was after:

from o in Orders
where o.OrderDate.Value.Year >= 1998 && o.Customer.Country == "France"
select new {Order = o, Customer = o.Customer};

The result of the above query in LINQPad and SQL Server Management Studio appear in my Matthieu Mezil Illustrates Use of AsEnumerable() That Mystifies Me post of June 14, 2008. The post also includes results of running Matthieu’s T-SQL batches which 1) return all 270 orders for 1998 or 2) are a LEFT OUTER JOIN of all 1998 orders with 23 French Customer records.

I’m sure I must be missing a point, but I don’t know what it is.

Update 6/15/2008 1600 PST: Adding AsEnumerable() causes immediate execution of the inner query which returns and OUTER JOIN resultset of 270 rows. Local (client-side) filtering reduces the number of rows to 23. Use of AsEnumerable() in this case unleashes bad mojo. See Matthieu’s comment and the second Update.

Eugenio Pace Posts a New SQL Server Data Services Sample: A Provider for BlogEngine.NET

Eugenio’s Another SSDS sample: BlogEngine.NET on SSDS post of June 11, 2008 describes his SQL Server Data Services (SSDS) provider’s source code for the BlogEngine.NET 1.3.1 ASP.NET blog project as follows:

  1. The SSDS based BlogProvider
  2. An SSDS based Membership & Role Providers for the web site
  3. Unit tests for all (with about 93% coverage for the provider)
  4. A simple tool for pre-loading the SSDS container with information that BlogEngine needs to start

He also says “The new SSDS BlogProvider also uses patterns & practices Unity application block to wire up dependencies.”

It’s related to the SSDS demo in Bill Gates’ Tech*Ed keynote and definitely worth a trial run.

Repeated from LINQ and Entity Framework Posts for 6/9/2008+ due to its importance.

Saturday, June 14, 2008

Matthieu Mezil Illustrates Use of AsEnumerable() That Mystifies Me

Matthieu’s AsEnumerable: not only to use unsupported methods post of June 13, 2008 discusses the differences in the results of a pair of complex LINQ to SQL Entities queries whose primary difference is use of AsEnumerable() to solve a problem obtaining Order instances with OrderDates in 1998 having French customers together with their Customer instances.

Updated 6/15/2008: See tests with Entity Framework below.

I would have used a LINQ to SQL or LINQ to Entities query with the results shown here in LINQPad to retrieve the Order/Customer instances with LINQ to SQL:

The preceding query generated the following T-SQL batch:

SELECT [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate], [t0].[RequiredDate], [t0].[ShippedDate], [t0].[ShipVia], [t0].[Freight], [t0].[ShipName], [t0].[ShipAddress], [t0].[ShipCity], [t0].[ShipRegion], [t0].[ShipPostalCode], [t0].[ShipCountry], [t2].[test], [t2].[CustomerID] AS [CustomerID2], [t2].[CompanyName], [t2].[ContactName], [t2].[ContactTitle], [t2].[Address], [t2].[City], [t2].[Region], [t2].[PostalCode], [t2].[Country], [t2].[Phone], [t2].[Fax]
FROM [Orders] AS [t0]
LEFT OUTER JOIN (
    SELECT 1 AS [test], [t1].[CustomerID], [t1].[CompanyName], [t1].[ContactName], [t1].[ContactTitle], [t1].[Address], [t1].[City], [t1].[Region], [t1].[PostalCode], [t1].[Country], [t1].[Phone], [t1].[Fax]
    FROM [Customers] AS [t1]
    ) AS [t2] ON [t2].[CustomerID] = [t0].[CustomerID]
WHERE (DATEPART(Year, [t0].[OrderDate]) >= @p0) AND ([t2].[Country] = @p1)
-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [1998]
-- @p1: Input NVarChar (Size = 6; Prec = 0; Scale = 0) [France]
-- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.30428.1

That batch returned the following result in SQL Server Management Studio:

which looked correct to me.

I wasn’t able to execute Matthieu’s queries in LINQPad, but I did execute his two T-SQL queries in SQL Server Mangement Studio.

Here’s the first result, which doesn’t apply the Country = ‘France’ constraint:

And here’s the second batch’s result set from the query that added AsEnumerable():

Which is a LEFT OUTER JOIN and doesn’t look to me like what Matthieu said he was looking for.

I’ve asked Matthieu to clarify his objective for me.

Update: 6/15/2008: In a reply to my comment on Matthieu’s post, he says:

My post wasn't clear so I change it.

I think the difference is that you do a LINQ to SQL query and I do a LINQ To Entities query.

To see if there were differences using an Entity Data Model, I created a simple WinForm app with a Northwind ObjectContext.

My LINQ to Entities query:

    using (NorthwindEntities ctxNwind = new NorthwindEntities())
    {
        var query = from o in ctxNwind.Orders
                    where o.OrderDate.Value.Year >= 1998 &&
                        o.Customers.Country == "France"
                    select new 
                    {
                        OrderID = o.OrderID, 
                        OrderDate = o.OrderDate,
                        CustomerID = o.Customers.CustomerID,
                        Country = o.Customers.Country 
                    };
        dgvQueryResult.DataSource = query.ToList();
    }

gave the expected result: 23 rows of orders with customer data in a DataGridView. 17 of the 23 rows are shown here:

I then ran Matthieu’s LINQ to Entities queries with and without AsEnumerable():

    using (NorthwindEntities ctxNwind = new NorthwindEntities())
    {
        var query = from oc in
                       from o in ctxNwind.Orders
                        where o.OrderDate.HasValue && 
                            o.OrderDate.Value.Year >= 1998
                        select new { Order = o, Customer = ctxNwind.Customers
                            .Where(c => c.CustomerID == o.Customers.CustomerID &&
                                c.Country == "FRANCE").FirstOrDefault() }
                    select new
                    {
                        OrderID = oc.Order.OrderID,
                        OrderDate = oc.Order.OrderDate,
                        CustomerID = oc.Customer.CustomerID,
                        Country = oc.Customer.Country
                    };
        dgvQueryResult.DataSource = query.ToList();
    }

and

    using (NorthwindEntities ctxNwind = new NorthwindEntities())
    {
        var query = from oc in
                       (from o in ctxNwind.Orders
                        where o.OrderDate.HasValue && 
                            o.OrderDate.Value.Year >= 1998
                        select new { Order = o, Customer = ctxNwind.Customers
                            .Where(c => c.CustomerID == o.Customers.CustomerID &&
                                c.Country == "FRANCE").FirstOrDefault() })
                            .AsEnumerable()
                    select new
                    {
                        OrderID = oc.Order.OrderID,
                        OrderDate = oc.Order.OrderDate,
                        CustomerID = oc.Customer.CustomerID,
                        Country = oc.Customer.Country
                    };
        dgvQueryResult.DataSource = query.ToList();
    }

Both of the preceding two queries returned the same data as shown in the last T-SQL example above: A 270-row outer join with 23 rows containing customer data. Adding the AsEnumerable() Standard Query Operator does nothing that I can determine.

My MezilEntitiesQueriesTest project is available for download here. The project expects to find the Northwind sample database attached to a local SQL Server 2005 Express instance (localhost\SQLEXPRESS).

2nd Update 6/15/2008 1545 PDT: The Light Dawns (sort of) … Bad Things Are Happening Here

Matthieu’s comment clarifies an invisible and probably unwanted effect of adding AsEnumerable() to the first query: My outer select clause returns scalar values from Customers and Orders. His outer select oc.Order clause returns only Orders entities and makes no request for Customer-related data.

Although Matthieu says near the beginning of this post, we “need to load into our context the right orders and customers.” Later, he says “the SQL request gets the orders we want and the customers we want,” the truth is, he doesn’t need or want the customers. If he had wanted the customers, he would have added oc.Customer[.Property] to his select clause.

LINQ to Entities’ (or LINQ to SQL’s) deferred execution implementation doesn’t write an extraordinary amount of T-SQL to return data that isn’t used. Adding AsEnumerable() caused immediate execution of Matthieu’s inner select clause, which includes a requirement for Customers. As a result, a very large number of cycles were wasted.

What’s worse, however, is that adding AsEnumerable() forced local filtering of the 270-row OUTER JOIN result set to include only 23 Customers+Orders instances in the query output.

Don’t try this at work. Also, it’s a good idea to execute the T-SQL batches of complex queries in Query Analyzer (or whatever) now and then to see if your LINQ to SQL or LINQ to Entities query is returning more rows that you’re using.

ASP.NET Dynamic Data: Scaffold a Custom Administrative Web Site with a LINQ to SQL Data Model in Less than Five Minutes

This screen capture sequence illustrates the “Use the Wizard to Generate Custom Pages” topic of the Scaffold Web Apps with ASP.NET Dynamic Data cover story for the September 2008 issue of Visual Studio Magazine. The topic describes how to create a fully-functioning file-system Web site from the Northwind sample database.

Step 1: Launch Visual Studio 2008 or Web Developer Express SP1, start a new file-system Web site and select the Dynamic Data Website Wizard (Preview) template.

Step 2: Accept the Generate a New Data Model from This Database option and select a connection to an SQL Server instance with the Northwind sample database installed.

Step 3: Select the only the original Northwind tables to install; omit the Regions and Territories tables. (The May 23, 2008 Dynamic Data preview was limited to LINQ to SQL as the data model. If your version of this dialog has a Data Context Namespace text box, leave it empty.)

Step 4: Scaffold all eight EntitySets for your project with List, Details, Edit and Insert pages.

Step 5: Accept the default customization options. You can remove features that use DetailsView or FormView controls or elect to edit or insert pages inline with GridView or ListView controls.

Step 6: Click Edit to open the Edit Fields dialog. Clear columns for properties of the selected entity that you don’t want to appear in the GridView or ListView control. (This dialog was not fully cooked in the May 23, 2008 release on which this post is based.) Click OK and then click Finish.

 

Step 7: Generating the scaffolding code will add several files to existing project folders. Mark the Apply to All Items check box and click Yes to avoid repeated appearances of the Merge folders message box.

Step 8: Review and optionally rearrange the singularized EntityType widgets. Notice the addition of a prebuilt NorthwindDataContextPartialClass file and addition of a CustomPages subfolder for each EntitySet. (Click image for an 1024 x 768 screen capture.)

Step 9: Press F5 to build and run the project, clicking OK to dismiss the Debugging Not Enabled message box.

Step 10: Notice the insertion of the Web site name after the Domain:Port name and number for the default and other pages.

Step 11: Click Products to display the Products ListView. Notice that a column for ProductID is missing and that Category and Supplier columns are out of sequence when compared with the original sequence of entity properties. (Click image for an 1152 x 864 screen capture.)

Appearance After Formatting with CSS and Minor Heading Changes

Following are customized versions of the forms shown in steps 10 and 11 as well as a Supplier details page with 11-point Calibri substituted for the approximately 8.5-point (76%) default Tahoma and Trebuchet MS fonts as well as color saturation increased.

Figure 12: /DynamicDataWebSite/Default.aspx

Figure 13: /DynamicDataWebSite/Products/List.aspx (Click for 1172 x 864 pixel version). Notice that the DynamicFilter dropdown lists are missing from Wizard-generated ListView pages.

Figure 14: /DynamicDataWebSite/Suppliers/Details.aspx$SupplierID=1

Sample code for the project, which includes customization by manipulating table and field metadata, will be available when the article publishes.

ASP.NET Dynamic Data: Generate a Dynamic Administrative Web App from an Entity Data Model in Less than Five Minutes

This screen capture sequence illustrates the “Generate a Dynamic-Page Web App” topic of the Scaffold Web Apps with ASP.NET Dynamic Data cover story for the September 2008 issue of Visual Studio Magazine. The topic describes how to create a fully-functioning ASP.NET Web Application from the Northwind sample database.

Step 1. Launch Visual Studio 2008 or Web Developer Express SP1, and select the Dynamic Data Entities Web Application template to use an Entity Data Model as the data access layer (DAL) for your project. (The Dynamic Data Web Site file-system project uses LINQ to SQL as its DAL.)

Step 2: Add an ADO.NET Entity Data Model DAL and give the model a descriptive name.

Step 3: Accept the default Generate from Database option in the first Wizard dialog.

 

Step 4: Select a connection to an SQL Server 2005 or 2008 instance of the Northwind sample database. (The computer name appears when localhost\SQLEXPRESS is specified as the Data Source.)

 

Step 5: Select the eight tables from the original Access version of the database and click Finish.

Step 6: After a few seconds the Entity Framework’s graphic object/relational mapping (O/RM) designer appears with the Model browser in the right pane. Rearranging the entity widgets and singularizing EntityType names is optional. (Click the image to open a full-size (1024 x 756) capture.)

Step 7: Open the Global.asax settings file and change the model name to NorthwindModel.NorthwindEntities and change ScaffoldAllTables from false to true. (Click the image to open a full-size (1024 x 756) capture.)

Step 8: Press F5 to compile and run the Web app with the ASP.NET Development Server (Cassini). Click OK to enable debugging.

Step 9: This subdued page opens to display a DynamicGridView of EntitySets. (The UI designers appear to have forgotten that the data source is an ObjectContext for EntitySets, not a relational table, and possibly are color blind.)

Step 10: Click the Products link to open the Products EntitySet in a DynamicGridView with three DynamicFilters for display by Discontinued state, Category and Supplier. Clicking a Category or Supplier link opens a DynamicDetailsView; clicking Order_Details opens a DynamicGridView of all Order_Detail entities that include the selected Product.

The three dropdown lists above the grid are DynamicFilter controls that enable filtering by Discontinued (Boolean) status (All, true, false), Category, Supplier or any combination of the three.

(Click the image to open a full-size (1152 x 864) capture.)

Step 11: Click a supplier link, such as Exotic Liquids, to display a DetailsView of the Supplier entity.

Optional Step 12: Singularize EntityType and navigation property (endpoint) names to correspond with association multiplicity. (Click the image to open a full-size capture.)

Appearance After Formatting with CSS and Minor Heading Changes

Following are customized versions of the forms shown in steps 9, 10 and 11 with 11-point Calibri substituted for the approximately 8.5-point (76%) default Tahoma and Trebuchet MS fonts as well as color saturation increased.

Figure 13: Default.aspx

Figure 14: /Products/List.aspx (Click for 1172 x 864 pixel version)

Figure 15: /Suppliers/Details.aspx$SupplierID=1

Sample code for the project, which includes customization by manipulating table and field metadata, will be available when the article publishes.

Thursday, June 12, 2008

LINQ and Entity Framework Posts for 6/9/2008+

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

Updated 6/11/2008 and 6/13/2008: See Added and Updated flags below.

Eugenio Pace Posts a New SQL Server Data Services Sample: A Provider for BlogEngine.NET

Eugenio’s Another SSDS sample: BlogEngine.NET on SSDS post of June 11, 2008 describes his SQL Server Data Services (SSDS) provider’s source code for the BlogEngine.NET 1.3.1 ASP.NET blog project as follows:

  1. The SSDS based BlogProvider
  2. An SSDS based Membership & Role Providers for the web site
  3. Unit tests for all (with about 93% coverage for the provider)
  4. A simple tool for pre-loading the SSDS container with information that BlogEngine need to start

He also says “The new SSDS BlogProvider also uses patterns & practices Unity application block to wire up dependencies.”

It’s related to the SSDS demo in Bill Gates’ Tech*Ed keynote and definitely worth a trial run.

Added: 6/13/2008

Phil Haack Promises Future Posts about Integrating Web Forms with MVC

He says in ASP.NET MVC And Dynamic Data Learn To Play Well Together of June 11, 2008:

I’ve been working on a post detailing a couple different ways to integrate WebForms and MVC, but life has been really busy for me lately. Hopefully I’ll get that to you soon.

In the meanwhile, you can probably learn all you need to know by looking at [MvcDynamicData.zip on this Code Gallery page.]

Added: 6/13/2008

Jim Wooley Demos LINQ to SQL with Plain Old CLR Objects (POCO) During the Tech*Ed Tweener Weekend

Jim’s LINQ to SQL support for POCO post of June 11, 2008 describes his Tweener demo as follows:

I created two separate projects. The first class library project, I created only targeting the 2.0 framework. As a result the project can not use any LINQ specific techniques. This will also allow us to consume the resulting objects in projects that do not have access to the newer framework, or to all of the namespaces. This is particularly important in cases like Silverlight. To call attention to the differences in the projects, I declared the 2.0 project in C# and the LINQ enabled project in VB.

His post includes a link to download the demo projects.

He also posted a link to his Tech*Ed Speaker Idol presentation, Screen scraping and creating Word documents with LINQ to XML.

Added: 6/13/2008

Julie Lerman Wants a Simpler Implentation of “Eager Deferred Loading” in Entity Framework

Danny Simmons provided an example of combining the Attach() and Include() methods with the CreateSourceQuery() surrogate for the Load method to return associated child and grandchild records in the ADO.NET Entity Framework and LINQ to Entities (Pre-release) forum’s Re: v2 Wish Lists - Add Yours Here thread.

Julie says in her Eager Deferred Loading of related entities post of June 11, 2008, that customer.Orders.Attach(customer.Orders.CreateSourceQuery().Include("Order_Details")) is “awfully convoluted,” but it works.

Added: 6/11/2008

Rob Conery Does MVC Storefront Part 14 with AJAX Control Toolkit and a Narrative Preview of IQueryable<T> in SubSonic 3.0

The screencast of Rob’s MVC Storefront Part 14: Ajax With Shawn Burke post of June 10, 2008 introduces ASP.NET AJAX to his MVC project to provide async form posting. Rob mentions that Phil Haack is in the process of AJAX-enabling the ASP.MVC library, so Rob’s code will be obsolete in a few months.

In SubSonic 3.0: IQueryable Update of the same date, Rob discusses the challenges of writing an expression tree with a visitor to translate LINQ Select queries to his SubSonic intermediate query language, thanks to Matt Warren’s Building an IQueryable Provider: Part II - Where and reusable Expression tree visitor post of July 31, 2007. Everyone working on LINQ-enabled data providers for databases or object/relational management (O/RM) tools is indebted to Matt for his detailed seven-part series.

Added: 6/11/2008

Maíra Wenzel Shows You How to Create Your Own Custom Metadata Attributes for ASP.NET Dynamic Data Entity Sets or Properties

Maíra’s Using custom attributes in Dynamic Data post of June 4, 2008 explains the process for writing and consuming custom metadata attribute classes by inheriting from Attribute and applying the AttributeUsage attribute. Her example changes the ForeColor of a property to a member of the KnownColor enumeration.

Added: 6/11/2008

Tech*Ed 2008 Panel Presentation: Occasionally Connected Systems

The following folks involved in occasionally connected systems (OCS) and ADO.NET Sync Systems:

  • Ginny Caughey - Microsoft MVP, Wasteworks
  • Steve Lasker - Sr. Program Manager, Microsoft SQL Server Compact
  • Rob Tiffany - Microsoft Mobility Architect
  • Rob Relyea - Architect, WPF Team
  • Liam Cavanagh - Sr. Program Manager, Microsoft Sync Framework

got together at Tech*Ed 2008 Developer to discuss storage, sync, programming model and UI for OCS. One of the new topics the panel discusses is republishing subscriptions for scalability.

The video is available here in multiple formats: Building Offline Enabled Applications [MP4] [WMV Hi] [WMV Lo]

Added: 6/11/2008

Scott Hunter Discusses the ASP.NET Dynamic Data Runtime on .NET Rocks

.NET Rocks Scott Hunter on Microsoft Dynamic Data (Show #349) post carries this deck:

Carl and Richard talk with Scott Hunter on Microsoft's Dynamic Data Runtime, which provides scaffolding and dynamic data services to developers.

ASP.NET Dynamic Data content starts at about 09:00.

At ~13:30, Scott mentions ADO.NET Data Services (Astoria) and LLBLGen Pro data layer for Dynamic Data and an intention to support NHibernate as a data layer. I don’t see an advantage to the use of Astoria, but support for LLBLGen Pro and NHibernate would be very welcome. You can read more about LLBLGen Pro support in Frans Bouma’s Dynamic Data and 3rd party o/r mappers is a fact post of May 1, 2008.

Scott Hanselman says the following about Dynamic Data and NHibernate:

In the future, watch for the possibility of Dynamic Data for POCO (my term, not the teams), Dynamic Data for Silverlight and Dynamic Data for MVC. Now is your opportunity to be heard. I'd like the idea of Dynamic Data for NHibernate myself, so I'm pushing for that. Feel free to engage in the Dynamic Data Forums or post bugs on this release in the issue tracker.

Scott Hunter confirms at ~47:00 that Dynamic Data for MVC is in the works for the next version.

Added: 6/10/2008 10:30 AM PDT

Updated 6/11/2008: Frans Bouma’s Dynamic Data and 3rd Party O/R Mappers Is a Fact post of May 1, 2008 described LLBL Gen Pro’s support for backing Dynamic Data. Frans is in the process of updating his sample provider to .NET 3.5 SP1 Beta.

Tim Anderson Misses the Point of My “Is the ADO.NET Team Abandoning LINQ to SQL?” Post

Tim’s Bet on ADO.NET Data Services, not LINQ to SQL post of June 10, 2008 starts:

So says Roger Jennings in his post Is the ADO.NET team abandoning LINQ to SQL? His main points in favour of ADO.NET Data Services (formerly Astoria):

  • It is the focus of more energetic development
  • It already has richer features
  • It supports multiple database engines, not just SQL Server

My post mentioned ADO.NET Data Services in passing as a client of Entity Framework (as is ASP.NET Dynamic Data.)

My point was that Entity Framework was a better bet than LINQ to SQL for a production object/relational mapping (O/RM) data layers because it’s getting the lions share of attention (and development resources) from SQL Server’s Data Programmability Group.

Update 6/11/2008: In a comment, Tim says he meant Entity Framework, not Astoria, and accidentally interchanged the two in his post. He changed the title and body of his updated post.

Paul Stovell Releases Bindable LINQ 1.0 Beta 1

Bindable LINQ is a LINQ to Objects implementation for Windows Presentation Foundation, Silverlight, and Windows Forms that provides data binding with collection change propagation. You can download the beta bits under a BSD license from CodePlex.

Paul's subsequent Bindable LINQ: Bindable Aggregates of June 10, 2008 provides insight on how Bindable LINQ responds to changes to LINQ aggregate values.

Note: WPF-oriented developers will appreciate Paul's detailed Article: Inductive UI’s with WPF Navigation Applications post of June 5, 2008, which was inspired by a Microsoft whitepaper, Inductive User Interface Guidelines, published in 2001.

Dare Obasanjo Takes on Joel Spolsky's Post About Live Mesh and Hailstorm

Hailstorm was the codename for .NET My Services, a heavily hyped but unsuccessful Web services initiative by Microsoft to make user data hosted on MSN available to the same users at other sites. Joel Spolsky's Architecture astronauts take over post of May 1, 2008 concludes that Live Mesh is Hailstorm reincarnated and doomed to failure because data synchronization "is just not a killer application."

Dare's Some Thoughts on Joel Spolsky's Live Mesh Rant of June 10, 2008 post points out:

Hailstorm has actually proven to have been a very visionary and accurate picture of how the world ended up. A lot of the information that used to sit in my desktop in 2001 is now in the cloud. My address book is on Facebook, my photos are on Windows Live Spaces and Flickr, my email is in Hotmail and Yahoo! Mail, while a lot of my documents are now on SkyDrive and Google Docs. Almost all of these services provide XML-based APIs for accessing my data and quite frankly I find it hard to distinguish the ideas behind a unified set of user-centric cloud APIs that was .NET My Services from Google GData.

He also notes that Mark Lucovsky is a former Microsoft employee who moved to Google. What Dare didn't mention is that Lucovsky was Hailstorm's architect and chief evangelist.

Frans Bouma Releases LLBLGen Pro v2.6 with Full LINQ Support

Frans' LLBLGen Pro v2.6 has been released! post of June 9, 2008 begins:

After almost 11 months of design, development, beta testing and adding final polish, it's here: LLBLGen Pro v2.6! This version, which is a free upgrade for all our v2.x customers, has a couple of major new features, the biggest of course being the full implementation of Linq support in our O/R mapper framework. The work on our Linq provider, which we've dubbed 'Linq to LLBLGen Pro', lasted almost 9 months and was discussed on this blog in a series of articles, which I'll linq to below.

He goes on to explain his problems with creating LINQ to LLBLGen Pro, lists what's new in v2.6, and adds links to the 15 detailed blog posts that chronicled his LINQ implementation.

Congrats, Frans!

Sync Framework Team Announces RC0 of Sync Framework and ADO.NET Sync Services in SQL Server 2008 RC0

The team’s Announcing Sync Framework v1.0 RC0 and Sync Services for ADO.NET v2.0 RC0 post of June 9, 2008 notes that SQL Server 2008 RC0 includes Sync Framework v 1.0 and Sync Services for ADO.NET 2.0 and provides the following download points for the SQL Server 2008 RC0:

There's no indication so far of availability of standalone bits that are compatible with SQL Server 2005.

Update 6/10/2008 3:15 PM PDT: Thanks to Mary Jo Foley for confirming that the Sync Framework will continue to be available as a standalone download.

Update 6/10/2008 10:30 AM PDT: According to the Data Platform Insider's SQL Server 2008 RC0 Available for Everyone post of June 10, 2008, Bob Muglia announced at Tech*Ed that everyone can download the RC0 and it's What’s New notes from:

  • Download SQL Server 2008 RC0
  • What's new in SQL Server 2008

    The team expects to release a CTP (Community Technology Preview) of the Sync Framework on devices in 2008Q3.

    Liam  Cavanagh Explains Hosted Services Synchronization in Gates's Tech*Ed Keynote

    Liam's Synchronization to Hosted Services and an Explanation of the Bill Gates Keynote post of June 9, 2008 points out that SQL Server Data Services (SSDS) was the central data storage point for synchronization of simulated blog posts between a local SQL Server instance and Windows Mobile devices.

    Mary Jo Foley Wonders Why It's Taken Microsoft So Long to Release Live Mesh

    Mary Jo's Are all (Microsoft and Apple) sync services created equal? post of June 9, 2008 says:

    Apple’s introduction of the successor to .Mac — a k a, MobileMe — raises the question as to what’s taking Microsoft so long to roll out Live Mesh.

    There aren’t a whole lot of details yet available on MobileMe, other than that it will allow cloud-based synchronization of data and devices. (And will make use of Microsoft’s ActiveSync technology, which Apple licensed from Microsoft in order to bring push e-mail to the iPhone, creating its “Exchange for the rest of us.”)

    From initial reports, MobileMe sounds like a combination of a Windows Live (the various Webified versions of the .Mac point products), Live Mesh (the Mobile Me sync service) and SkyDrive (the Mobile Me cloud-based storage). It is slated to be available to customers in July for a (pricey) $99, which includes 20 GB of storage.

    She also reports having a difficult time getting Microsoft executives to explain why Microsoft didn't use the Sync Framework for Live Mesh. She says:

    All I could get out of them was Live Mesh is the P2P, out-of-the-box sync solution and Sync Framework is the customizable, developer-focused sync solution. The only place (so far) where the two meet: FeedSync.

    Very strange.

    Note: Skydrive stores the ~500 images for this blog and has delivered them with no observed outages or performance issues. The only problem I've encountered is a brief interval (an hour or less) when I couldn't upload images; downloading wasn't affected.

    Skain Compares Several Techniques for Bulk Deletions with LINQ to SQL

    Skain's Bulk Deletes in Linq to SQL update to an April 8, 2008 post chronicles his search for a bulk deletion method for LINQ to SQL that doesn't retrieve each object into memory and delete it while executing the DataContext.DeleteAllOnSubmit() method.

    His final DataContext.BulkDelete() extension method provides a better solution, however there are references in the comments to alternative solutions.

    CoÅŸkun Sunali Uses the LinqDataSource as a DataPager Workaround for the ListView Control

    His Using DataPager with Code-Behind Data Source post of June 9, 2008 says:

    Some of you might have already realized that DataPager does its job only if you use a DataSource control. For instance, if you want to set a ListView’s DataSource property in page’s Load event and expect DataPager control to successfully page the ListView control, it means that you will need to spend your hours to find why it does not work.

    CoÅŸkun provides the simple source code for the workaround.

    Strange Exception Generated by Open File Dialog in a Windows Form Backed by the Entity Framework

    Sumeet reports in his Entity framework and OpenFileDialog post of June 8, 2008 that closing, not canceling, an OpenFileDialog in a Windows form of a project using the Entity Framework as a data access layer causes an exception on the next call to the ObjectContext.

    The problem appears to be a change to the Environment.CurrentDirectory property, which must be reset with an Environment.CurrentDirectory = Application.StartupPath instruction.

    John Papa Posts a Linklist to Silverlight 2 Beta 2 Resources

    John's Silverlight 2 Beta 2 Rundown post of June 8, 2008 provides 13 links to early Silverlight 2 Beta 2 Resources, including Shawn Wildermut's Using ADO.NET Data Services in Silverlight 2 Beta 2.

    Mike Tulty applauds John's list in his Silverlight 2 Beta 2 - What's New? post of June 9, 2008.

    DataGrid Breaking Changes and Behavior Differences in Silverlight 2 Beta 2

    The Silverlight SDK Team's DataGrid Control Beta 2 Changes of June 6, 2008 points to the DataGrid Beta 2 Breaking Changes post of the same date, but also includes behavior changes for Autogenerated Columns and Automatic Sizing.

    Note: A substantial amount of Silverlight 2 Beta 2 content is included in these posts because of the new Silverlight Client Library for ADO.NET Data Services.

    Shawn Wildermuth Explains How to Debug ADO.NET Data Services with Fiddler2

    Shawn's Debugging ADO.NET Data Services...with Fiddler2 of June 6, 2008 provides detailed instructions for using Fiddler2 with ADO.NET Data Services, including adding the period after the IP address to make localhost data appear.

    He concludes:

    One caveat, this is the first release of the ADO.NET Data Services' Silverlight Client Library so give it time to improve some of the performance issues.  But like other data access libraries, sometimes small changes can make large improvements in performance.

    Shawn also announced that he's updated the following Silverlight 2 sites and projects to Beta 2:

    Off-Topic: Windows Live Writer Technical Preview for Build 14 Appears Solid

    I've been posting with the Windows Live Writer (WLW) Technical Preview for build 14 since its release on June 2, 2008 and haven't encountered a problem so far.

  •