Showing posts with label Dynamic LINQ. Show all posts
Showing posts with label Dynamic LINQ. Show all posts

Monday, November 24, 2008

LINQ and Entity Framework Posts for 11/17/2008+

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

Updated 11/24/2008 8:00 AM PST
• Updated 11/21/2008 9:00 AM PST
• Updated 11/20/2008 5:30 PM PST

Entity Framework and Entity Data Model (EF/EDM)

• Ayende Rahien reports substantial increases in NHibernate downloads and posts to the NHibernate users group in his The NHibernate Community post of 11/22/2008.

Rick Anderson’s How to create an updateable view with ADO Entity Framework and with LINQ to SQL post of 10/03/2008 describes what the title claims. (Thanks to Steve Naughton for the heads up on Rick’s MSDN blog, which I wasn’t watching but am now.)

•• Frans Bouma takes the EF Team to task for their plans to force developers to write their own client-side update tracking code, not to mention rolling their own “wire-level format for changes sent from client to another tier,” in his Baby-sitter Framework 2.0: Change tracking in the EF v2, it's still your problem post of 11/21/2008.

•• Ayende Rahien agrees with Frans in his Stealing from your client post of 11/21/2008. Ayende says “This Is Broken, By Design.” I agree with Ayende and Frans.

Jeff Derstadt, Jaroslaw Kowalski, and Diego Vega posted N-Tier Improvements for Entity Framework [v2] on 11/19/2008, which proposes the following “goal” for future n-tier implementations:

Entity Framework won’t define its own unique representation for the set of changes represented in an N-Tier application. Instead, it will provide basic building block APIs that will facilitate the use of a wide range of representations.

My Entity Framework Team Abandons Unified N-Tier Architecture for v2 provides more details about the team’s decision to abandon a unified n-tier architecture for EF v2.

Milind Lele mentions that VS 2010 will support drag-and-drop data binding for WPF in his Drag-drop data binding for WPF in Visual Studio 2010 (Milind Lele) post of 11/19/2008 and notes:

In VS2010 we've added support for EDM in the data sources window. Thus when you add an EDM to your project, the entities show up in the [D]ata [S]ources window. You can simply drag the entities and drop them onto your WPF form or control to bind them.

His earlier Drag-Drop Data Binding For WPF post of 11/8/2008 has a screen capture of Northwind EntitySets in the Data Sources window.

John Papa offers Code from DevConnections 2008 in Las Vegas (11/18/2008) for the following sessions:

  • Implementing the Entity Framework
  • Data Access with Silverlight 2
  • Developing with Enterprise Library Data Access Application Block

Kim Major’s Entity Framework – Some common hurdles post of 11/17/2008 describes how his repository implementation deals with the following issues:

  • No eager loading. Need to specify .Include(“”) for every query.
  • No way to make to turn change tracking on/off except from changing every query.
  • A bug that prevents simple queries where nvarchar columns are used in the criteria.
  • A designer error with a cryptic error message.

His earlier Data Access With The Entity Framework (11/12/2008) and Testable Data Access With The Repository Pattern (11/14/2008) posts describe Renaissance Computer Systems Ltd.’s EF-based framework.

LINQ to SQL

••• Visual Studio Magazine’s “Speed O/R Mapping with LINQ to SQL” cover story by Roger Jennings for the December 2008 issue carries the following deck:

LINQ to SQL continues to be a top contender in the .NET object/relational mapping tool market despite Microsoft's promotion of the Entity Framework as one of the "Pillars of SQL Server 2008: Dynamic Development."

The article includes a table that compares LINQ to SQL and Entity Framework features and a “Visual Studio 2008 SP1 Add-Ins Remove LINQ to SQL Roadblocks” sidebar that describes Huageti Systems’ DBML/EDMX Tools utility for LINQ to SQL and Entity Framework and Damien Guard’s T4 template for customizing LINQ to SQL partial class code generation.

The LINQ to SQL Featured in Visual Studio Magazine’s December 2008 Cover Story post of 11/24/2008 adds related OakLeaf blog links and a couple of minor corrections to the text and table.

Rick Anderson’s How to create an updateable view with ADO Entity Framework and with LINQ to SQL post of 10/03/2008 describes what the title claims. (Copied from the “EF/EDM” topic.)

Kristofer Andersson’s Tools - Part 6 - Add-ins - “Model First” in Linq-to-SQL (and Entity Framework) post of 11/21/2008 describes a new feature of his Huagati DBML/EDMX Tools that enables generating the underlying database from a LINQ to SQL O/R Designer model and then incrementally updating the database schema with change scripts as the model matures.

Incremental updates are important because LINQ to SQL’s current model-first implementation [re]generates the entire database for each design update. The EF team’s stated intention for EF v2 is exactly the same. In both cases, the developer must recreate all data, relationships, indexes, etc. manually or author a hand-written change script. Regenerating the database for model changes is not acceptable in a production O/RM tool.

Kris’s post includes screen captures of an example that adds two tables related to Northwind’s Employees table. If you’re working with LINQ to SQL or EF, you need the Huagati DBML/EDMX Toolkit.

Deepak ? demonstrates how to Dynamic Sort With LINQ To SQL in this 11/19/2008 post. He writes a complex method with the Expression type, which he finally simplifies to a simple GetSortedEmployees<T> function with a lambda expression to specify the OrderBy predicate.

Matt Warren’s Building a LINQ IQueryable Provider - Part XII post of 11/17/2008, following a four-month hiatus, wraps the code from his previous 11 episodes into a single IQToolkit project that also includes testing code. Matt describes the changes from the earlier, incremental code base:

One of the first things you'll notice when you take a look at the source is that I changed it quite a bit.  I moved code around, changed names gratuitously, added & removed classes and broke a lot of continuity with the prior versions. One of the biggest changes is that the code is no longer just a sample.  All those internal classes are public, the project builds as a DLL, the tests are hosted separately and the namespace is no longer 'Sample.'

Bravo, Matt! A vituoso performance.

••• Matt posted his IQToolkit source code to CodePlex on 11/21/2008

Deepak ?’s  Enum Support With LINQ To SQL And SqlMetal post of 11/18/2008 describes his approach for using an enum in code. His “solution is to generate dbml file using SqlMetal, then run a custom process which modifies dbml to make it enum ready and finally generate code using SqlMetal looking over dbml file.”

LINQ to Objects, LINQ to XML, et al.

Bart De Smet’s Dude, Where’s My LINQ DML? post of 11/22/2008 discusses adding DML for “batch updates that don’t require client-side input or computation.” Bart demonstrates attempts at “Updateable LINQ to Objects,” “Updateable remotable LINQ,” and “Introducing IUpdateable<T>”, but bails with the following:

I’ll leave a concrete implementation of an update provider to the inspired reader; a basic prototype for SQL (only allowing columns to be updated with constant string or integer values) worked like a charm.

Bart: How about providing your “basic prototype for SQL” code?

Note: As reported last week, Rob Conery “added some spice to [SubSonic 3.0] and now we have a batch-updatable (read: one connection, one sql execution) Add/Update/Delete for the Repository which you can download here ([he]'ll include this in subsequent releases).”

Eric White demonstrates LINQ to XML generating an Inner Join of Two Excel Tables directly from the spreadsheet.Table(“TableName”) sources in this post of 11/20/2008.

LinqMaster’s Iterators, Lambda, and LINQ post of 11/20/2008 claims to be “The path to understanding Lambda and LINQ.” Sounds like LinqMaster is attempting to emulate Siddhartha Gautama in the LINQ department.

Aghy (Agnes Molnar) points to an updated version of LINQ4SP (LINQ to SharePoint) RC2 with its timebomb extended to 1/1/2009 in her Linq4SP - RC2 timebomb extended post of 11/20/2008. The earlier version expired a few days ago (in advance of the availability of paid licenses.)

Mike O’Brien’s Importing and Exporting Data Using Linq post of 11/18/2008 demonstrates how to export data from a SQL Server table to XML using LINQ to SQL and LINQ to XML.

ADO.NET Data Services (Astoria)

Marcelo Lopez Ruiz’s Limiting how many entities are returned from an ADO.NET Data Service post of 11/19/2008 explains that you can limit the number of entities on the server as well as with the $top query string option. Marcelo says:

MaxResultsPerCollection allows you to limit not only the number of entities returned at the top level of a request, but also at each collection within, so clients can't use '$expand' to overwhelm the server. Because a batch request can have multiple queries, you can combine that with MaxBatchCount.

However, use of these constraints is likely to throw exceptions.

He also cautions not to forget the dollar-sign prefix for system query parameters (options) in Filter not working in ADO.NET Data Services? of 11/18/2008

Brandon Bilinsky announced on 11/19/2008 that Like a Version; AtomPub Compliant for the Very First Time v2 of the Google Data APIs is fully compliant with the AtomPub standard (RFC 5032.) Like Astoria, Data APIs v2 uses HTTP ETags for optimistic concurrency management. Google’s Java and .NET client libraries have been updated with v2 support.

Rick Strahl’s ASP.NET Connection Session Slides and Samples Posted of 11/17/2008 describes and provides links to these sessions:

  • Using WCF for REST and JSON Services with ASP.NET
  • Using jQuery with ASP.NET
  • Dealing with Long Running Requests in ASP.NET

ASP.NET Dynamic Data (DD)

Rick Anderson solves a problem that occurs when you scaffold AdventureWorks’ CustomerAddress column in his Improving the FK field display: Showing two fields in Foreign Key columns with EF post of 11/21/2008. By default, DD turns the table’s first string column into a lookup field, in this case the Title field. Rick corrects the problem “by creating and annotating a partial class for the  Customer entity.”

Jonathan Carter’s Dynamic Data: The Little MetaModel That Could post of 11/20/2008 delve deeper into DD’s metadata classes: MetaTable and MetaColumn.

• Jonathan Carter posts the third episode as Dynamic Data: Models, MetaModels And Everything In Between on 11/19/2008. He notes that Dynamic Data provides …

A common meta-model system for describing data models with a higher semantic that a UI can leverage to be smarter by default. Out of the box, it includes providers for LINQ-To-SQL and the Entity Framework (which is why it has gotten a reputation for working solely against databases), but nothing stops it from working against any other data source. In fact, prototypes already exist that have Dynamic Data working against an ADO.NET Data Service, as well as a SQL Data Service.

Jonathan Carter follows up the first DD episode with Dynamic Data: Kickin’ It Old School of 11/19/2008, which provides a “contextual explanation as to why you might want to [leverage Dynamic Data within an existing web application], and what benefits may exist.

Jonathan Carter’s Dynamic Data: Come For The Scaffolding, Stay For Everything Else post of 11/17/2008 is the first episode of a new series about ADO.NET Dynamic Data. You might recall Jonathan’s earlier multipart series about ADO.NET Data Services.

Azure, SQL Data Services (SDS) and Cloud Computing

Roger Jennings uploaded the OakLeaf Systems Azure Table Services Test Harness to Windows Azure on 11/23/2008 and it’s now live at http://oakleaf.cloudapp.net/Default.aspx. For more details, see Windows Azure Test Harness Is Live! of the same date. A few features are disabled in the publicly available version.

Mike Amundson observes that SDS currently supports JSON (and ATOM) wire formats with Astoria functionality in his reply of 11/20/2008 to the JSON as alternative to XML for REST requests? thread in the SQL Data Services (SDS) - Getting Started forum.

The SDS Team’s Evan Basilik commented on the same date that “It does work, but is not an entirely "baked" part of the product.” Later posts request reassurance that, unlike Astoria, SDS will continue to support Plain Old XML (POX).

James Urquhart’s Do Your Cloud Applications Need To Be Elastic? post of 11/21/2008 quotes Citrix’s Cris Flex’s Cloud Economics 101 - Part 1 post of 9/27/2008 compares the cost of on-premises versus cloud computing on Amazon’s EC2. James concludes that cloud computing (with EC2) is only competitive with on-premises operations if you take full advantages of the ability to add and remove instances to satisfy periodic load peaks.

(Chris’s Cloud Economics 101 Part 2 - Premise Plus Cloud post of 10/13/2008 analyzes supplementing on-premises hosting with cloud computing for short-term demand spikes.)

Roger Jennings added the last three episodes to his Azure Storage Services Test Harness series:

  • Table Services 7 – Testing for Table Existence at App Startup Only (11/22/2008)
  • Table Services 6 – Paging LINQ to REST Query Result Sets (11/22/2008)
  • Table Services 5 – Generating Classes/Collection Initializers with LIMOG v2 (11/21/2008)

    • Pat Helland’s An Interview with .NET Rocks while I Was at Barcelona Last Week post of 11/20/2009 contains a link to an interview about the five sessions Pat presented at Tech*Ed EMEA 2008 Developer:

    1. When You Have Too Much Data, “Good Enough” is Good Enough
    2. Building on Quicksand
    3. RIAs and Emissaries
    4. Metropolis: Buildings and Applications
    5. Title Missing

    All have some relationship to cloud computing, but the interview emphasized topic #1.

    Roger Jennings added two new episodes to his Azure Storage Services Test Harness series:

    The goal is to wrap up the series by the end of this week.

    David Aiken’s illustrated Peeking [into] Windows Azure Queues using Windows PowerShell post of 9/12/2008 shows you how to use the CloudDrive Windows PowerShell provider from the Azure sample projects to browse and read queues.

    John Foley notes in his Next Headache: Cloud Chaos post of 11/19/2008 that:

    InformationWeek is preparing a report on how to get into cloud services, a hands-on guide to help you make a smooth transition, which we will publish in December. Those who want to ride the learning curve with peers should consider attending Cloud Connect, an "unconference" with a learn/develop/demo format. The event, co-sponsored by InformationWeek, takes place Jan. 20 to 22 at the Computer History Museum in Mountain View, Calif.

    So far, the “unconference” agenda has a severe case of the “Berkeley Vagues.”

    Steve Marx eliminates the performance hit caused by executing the CreateTablesFromModel() method against Azure Table Services on each server round trip in his Try to Create Tables Only Once post of 11/18/2008. I put his approach to work in the Global.asax.cs file added to my Azure Storage Services Test Harness.

    Oren Melzer’s The CardSpace “Geneva” Selection Experience post of 11/17/2008 explains the “newly designed selector in the new CardSpace ‘Geneva’ beta.” CardSpace is one of the authentication methods for the Azure Services Platform.

    Microsoft announced its Microsoft Business Productivity Online Standard Suite (MBPOSS) on 11/17/2008 and Mary Jo Foley analyzed its SharePoint capabilities in her What does ‘SharePoint in the cloud’ really mean? post of the same date. MBPOSS offers Exchange Online, SharePoint Online, Office Live Meeting, and Office Communications Online (later) “in the cloud” to potential users starting at $15.00 per month.

    Werner Vogels describes Amazon Web Services’ new edge-based content distribution network (CDN) for S3 called CloudFront in his Expanding the Cloud: Amazon CloudFront post of 11/17/2008. Nice name, by the way.

    SQL Server Compact (SSCE) 3.5 and Sync Services

    Steve Lasker’s Tech Ed EMEA 08 Powerpoints and Demos post of 11/19/2008 has links to slides and demo code from his two presentations:

    • DAT314  Unlocking the Power of SQL Server Compact 3.5
    • DAT405 Managing and Versioning Client Databases 

    Miscellaneous (WPF, WCF, MVC, Silverlight, etc.)

    Sam Gentile posted the 11th member of his SOA: Making the Paradigm Shift Part series on 11/23/2008 as Introduction to WCF: Architecture and the "ABCs" of Indigo." Sam says “The focus of this post is to show "Hello Indigo" code in a step-by-step manner. We will dive deep into the Indigo Architecture in the next installment of this series.”

    Rick Strahl attempts to divine the appropriate data transfer model to SQL Server parameterized stored procedures in his Silverlight and Data Communications post of 11/20/2008.

    David Betz’s Understanding WCF Services in Silverlight 2 of 11/16/2008 is a full-length tutorial for “access[ing] WCF services using Silverlight 2 without magic. There will be no proxies, no generated code, and no 3rd party utilities. Just raw WCF.”

    Rico Mariani’s The Visual Studio Tech Roadmap -- Starring Visual Studio 2010 post of 11/18/2008 presents Visual Studio’s chief architect’s view of the goals for VS 2010 and later, including a reference to future cloud-computing capabilities and tools (see the Danny Thorpe item below.)

    Simon Segal explains how he’s Moving on from Windows & Web Forms to Silverlight 2.0 in this detailed post of 11/18/2008.

    Scott Guthrie notes that Silverlight 3 will have “richer data-binding support” in his Update on Silverlight 2 - and a glimpse of Silverlight 3 post of 11/16/2008.

    Dare Obasanjo’s Live Framework (LiveFX), Is it Microsoft's GData or Something More? post of examines LiveFX and concludes:

    The client-side Live Operating Environment is a technology whose benefits elude me. I admit it is kind of cool but I can't see its utility.

    Danny Thorpe responds in his Client-Side Live Operating Environment: What’s It For? post of 11/18/2008 that “The answer, in a word, is ‘offline.’” Danny was a Principal Software Development Engineer for LiveFX who left Microsoft in October 2007 and returned in May 2008. He joined the Visual Studio incubation team that’s “working on stuff to make accessing Windows Live services easier for developers,” and is now Principal Engineer, Cloud Computing Tools.

    Kristofer Andersson’s Data Model - Basics - Part 11 - The HuagatiRes data model converted to “M” post of 11/15/2008 describes his conversion of the HuagatiRes airline passenger reservation system data model into an Oslo M script with a “code snippet that extracts schema, type, table, column, foreign key, and index defs and generates M files.” Kris says:

    Give it a connect string and an output folder and it will generate one M file per schema in the database you point it at, complete with code comments (based on object names and extended property descriptions) and all. Even [commented out] index definitions - prepared for the day when M gets support for index definitions.

    P.S.: Aker Brygge is the site of a former Norwegian shipyard (near Oslo) that’s been converted into a “shopping center with shops and restaurants, a cinema, office space, and apartments. Additionally, there is a small boat harbour, and a terminal for the ferries to Nesodden (across the Oslo fjord).”

    Kathleen Richards quotes me in her A Tale of Two 'Cities' article about Oslo and Dublin for Redmond Developer News’ November edition:

    Data-driven app developer Roger Jennings, a contributing editor to Redmond Developer News' sister publication Visual Studio Magazine and OakLeaf Systems blogger, says with Oslo Microsoft is moving toward a repository for componentized software. The company's intention is to make the visual designer Quadrant usable by business analysts -- to modify workflows, for example -- but whether that will work is unclear.

    "My feeling about Oslo is that they're trying to get business analysts involved in the design process, but not necessarily doing the design," says Jennings.

  • Saturday, March 01, 2008

    LINQ and Entity Framework Posts for 2/25/2008+

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

    New "Model Domain Objects with the Entity Framework" Article in Visual Studio Magazine for March 2008

    Visual Studio Magazine's March 2008 cover story is my "Model Domain Objects with the Entity Framework" article. Here's the deck:

    Microsoft's ADO.NET Team readies Entity Framework and Tools 1.0 for release as a VS 2008 add-in with enterprise-level features that LINQ to SQL doesn't offer—domain object modeling, flexible inheritance techniques, multiple database vendors, and do-it-yourself n-tier deployment.

    The story covers new and modified EF features since my "Objectify Data with ADO.NET vNext" article in the October 2006 issue.

    A sidebar describes Danny Simmons' EntityBag (Perseus) project for "do-it-yourself n-tier deployment."

    Erratum: Entity SQL does have a JOIN command but it's used to join unrelated entities only. The eSQL NAVIGATE command is used with associations and navigation properties, which represent INNER JOINs at the conceptual level.

    Added: 3/1/2008

    ADO.NET Data Services (Astoria) Becomes the Framework for All Window Live Services

    In honor of the announcement by Pablo Castro that "all Windows Live services can be accessed using AtomPub" ADO.NET Data Services has been rechristened the "ADO.NET Data Services Framework." [Emphasis added.] This term was occasionally used in documentation for Astoria's December 2007 CTP. Here's the official story from MIX08:

    Accessing Windows Live Services via AtomPub

    Friday, March 7 8:30 AM - 9:45 AM, Delfino 4105
    Speaker(s): Pablo Castro
    Audience(s): Technical
    Session Type: Breakout

    Come learn how Microsoft is moving towards a unified approach for accessing online services based on AtomPub. We cover how all Windows Live services can be accessed using AtomPub as well as how integrated Microsoft Visual Studio support including ADO.NET Data Services Framework (aka Project "Astoria") allows anyone to easily develop, deploy, and access online services using AtomPub. [Emphasis added and typo fixed.]

    Whaddya bet that everyone continues to call it "Astoria?"

    Added: 3/1/2008

    Dan Wahlin Posts Layered LINQ to SQL Sample Application

    Dan's Building an N-Layer ASP.NET Application with LINQ, Lambdas and Stored Procedures (Updated) post of February 28, 2008 provides a description of a four-layer (presentation layer, business layer, data layer and model layer) ASP.NET/LINQ to SQL demo application that lets you choose between LINQ, lambda functions, and stored procedures for queries. Dan databinds his ListView and GridView controls to an ObjectDataSource (rather than a LinqDataSource), apparently because of the multiple query types he uses.

    The demo project, which is available for download from a link on his above post, is for his presentation at ASP.NET Connections Orlando in April:

    ADX211: Building N-Tier Applications with LINQ
    Dan Wahlin
    Creating a modular and maintainable application architecture is always a key part of the application development life cycle. In this session you'll learn how to build N-Tier/N-Layer applications that leverage Language Integrated Query (LINQ) to minimize development time while still maintaining module design practices. Topics covered include using the Visual Studio 2008 LINQ to SQL designer, using data context objects, and performing different types of LINQ queries.

    Dan's earlier LINQ and Lambdas and Sprocs....Oh My! post explains why he uses the three query types.

    Note that the demo is N-Layer, not N-Tier.

    Added: 2/29/2008

    Doug Rothaus and Avner Aharoni Start LINQ to XML VB Cookbook Series

    Doug says in the VB Team's VB XML Cookbook, Recipe 1: XML Transformations using XML Literals (Doug Rothaus) post of February 29, 2008:

    I was working on a blog entry about replacing XSLT transforms with Visual Basic XML Literals. As the entry progressed, I noticed that it was really, really long. So, Avner Aharoni and I talked things over and we decided to break it up into multiple entries and start a series, much like the LINQ Cookbook that was started a few months back.

    This first episode shows you how to replace <xsl:copy-of>, <xsl:for-each>, <xsl:template>, <xsl:if>, <xsl:value-of>, and <xsl:attribute> elements as well as use XML Axis Properties in place of XPath.

    As I said in a comment to this post:

    Scott Guthrie doesn't worry about long posts. His First Look at Using Expression Blend with Silverlight 2 post of February 28, 2008 was about 15 feet long. There's no question about the popularity of Scott's posts.

    These linkblog posts sometime reach close to that length, but mine don't come anywhere near the popularity of his tutorials.

    Added: 2/29/2008

    Christian Kleinerman's Video Extols New Developer Features in SQL Server 2008

    This might seem off-topic but Channel9's Christian Kleinerman: SQL Server 2008 for Developers video segment (posted February 29, 2008) covers some topics of specific interest to LINQ to SQL and Entity Framework developers, to wit:

    • SQL Management Studio improvements including IntelliSense
    • New Data Types for just dates or times (no more storing time when you only need the date)
    • New Hierarchical data support .IsDescendent(), that can automatically pull a hierarchical view of data (no more custom recursive queries)
    • New Grouping Sets statement which enables you to automatically group dimensions in a query for easy aggregation and reporting
    • New Merge statement which provides automatic insert/update semantics for keeping multiple data sources in sync
    • New FileStream attribute that enables you to include files that are stored in the server file system, but can be managed by SQL Server
    • New data types and support for Geodata and geometry
    • New support for optimizing "empty" or row/column tables using the sparse keyword

    .IsDescendent() relies on the new hierarchyid data type, whose value represents the encoded position in a tree hierarchy.

    You can learn more about converting a table that is structured as a parent/child hierarchy and move the data into a new table that represents the hierarchy and then manipulate that data in the Tutorial: Using the hierarchyid Data Type topic. Not surprisingly, the tutorial uses the AdventureWorks Employee table to construct a "reports-to" hierarchy to replace a self-join. The same technique could be applied to the Northwind Employees table.

    Note: It's not clear yet how or if LINQ to SQL or the Entity Data Model will suppory hierarchyid tables.

    Caution: Euan Garden notes in his SQL Server 2008 CTP's and "Leap Day" post of February 29, 2008 that SQL Server 2008 services will not start during the 24 hours of February 29, 2008 GMT.

    He recommends: Do NOT stop or restart any SQL Server 2008 services during those 24 hours. (There are no workarounds.)

    It's fortunate that Katmai didn't release at the release party or earlier. There would have been bad news today.

    Added: 2/29/2008

    Chris Rock Attacks Dynamic LINQ to SQL Queries

    Orlando, FL developer Chris Rock (not the comedian) digs into creating Dynamic LINQ queries with Joe and Ben Albahari's LinqKit Predicate Builder in the LINQ TO SQL Dynamic Queries post of January 24, 2008 and the follow-up LINQ TO SQL Dynamic Queries #2 (Or statements) of February 27, 2008.

    The latter post demonstrates that you can create dynamic LINQ to SQL Queries with AND, as well as OR clauses, in C# or VB.

    Added: 2/29/2008

    Use LINQ to Manipulate Excel Data

    Denis van der Stelt's Getting data from Excel the fast way, using LINQ post of February 29, 2008 shows you how to process Excel data with the Microsoft.Jet.OLEDB.4.0 data provider, a DataTable for the worksheet and LINQ to DataSets.

    The whole process, including enumeration, takes only nine lines of C# code (if you consider the LINQ expression to be one line.)

    An alternative is to use Cozy Yamaguchi's LINQ to Excel, the source code for which is downloadable from CodePlex. (There was no release when this post was written.)

    Added: 2/29/2008

    Charlie Calvert Updates List of Third-Party LINQ Providers

    Charlie's Link to Everything: A List of LINQ Providers post of February 28, 2008 lists 22 third-party LINQ providers (Bart De Smet renamed LINQ to LDAP to LINQ to Active Directory).

    My list of LINQ to ... labels at the left has a few more items but includes Microsoft providers, such as LINQ to REST (part of the ADO.NET Data Services client library), and some that are works in progress (e.g., LINQ to LLBLGen Pro.)

    A few significant third-party LINQ providers/APIs missing from Charlie's post are:

    Added: 2/29/2008

    David Treadwell: Atom and AtomPub Support for Windows Live Photos and Application Based Storage

    The February 27, 2008 David Treadwell on New and Updated Windows Live Platform Services post to the Windows Live Dev News blog includes an "Atom Publishing Protocol (AtomPub) as the future direction" topic that states:

    At MIX we are enabling several new Live services with AtomPub endpoints which enable any HTTP-aware application to easily consume Atom feeds of photos and for unstructured application storage (see [here] for more details). Or you can use any Atom-aware public tools or libraries, such as .NET WCF Syndication to read or write these cloud service-based feeds. [Emphasis added.]

    For more information, see Atom and AtomPub Support Extended to Windows Live Photos and Application Based Storage of February 29, 2008.

    David Treadwell is Microsoft's Corporate Vice President, Live Platform Services, which include "unified identity and directory, data synchronization, transport and presence, among others." He's also the Microsoft representative to DataPortability.org.

    Added: 2/28/2008 Moved to separate post: 2/29/2008

    Marcin Dobosz Details Dynamic Data's Project Templates

    In his Project templates just got bigger post of February 27, 2008, Marcin contrasts the precocial Visual Studio 2008 templates used by ASP.NET Dynamic Data with the altricial templates of most other VS project types. (Not being a biologist, this was the first time I can recall hearing these terms.)

    ASP.NET Dynamic Data's December CTP supports LINQ to SQL data sources only because the EntityDataSource control wasn't available for the Entity Framework. David Ebbo mentioned in a comment to his Dynamic Data screencast is now available! post of December 12, 2007, that;

    Linq To Entities will indeed have improved support for this [many:many associations], and generally make it easier.

    As of the December Preview, DynamicData only supports Linq To Sql, but the next public build will include Entities support. [Emphasis added.]

    Hopefully, Marcin's pre-MIX post means that the "next public build" will accommodate an available EntityDataSource control.

    Added: 2/28/2008

    Rob Conery Uses LINQ to SQL's Contains() Operator for Predictive Modeling SQL IN Predicates

    Rob starts his Creating IN Queries With Linq To Sql post of February 27, 2007 with:

    Props on this one go to Scott Hanselman who pulled me back from the edge of the cliff last night. I was particularly distraught in getting a MIX demo together where I had to do some queries using LINQ, and I couldn’t for the life of me figure out how to fashion an IN query! With Scott’s help (and patience) I figured it out, and thought I should blog for my own reference, at least.

    Jim Wooley beat Scott and Rob to the punch on the use of Contains with an array last August. I left this comment:

    I believe Jim Wooley was the first to suggest the Contains trick in his Use the new LINQ “Contains” extension method for the SQL “IN” clause post of August 06, 2007.

    At least that’s the first instance I’ve seen.

    But then he goes on in another post to describe "LINQ gymnastics" for predictive cross-sell modeling—the technique for showing "items that other people bought, most often, when they bought the product the user just added to their basket."

    The solution, described in his LINQ Gymnastics: Creating A Predictive Query With LINQ post of the same day, requires five chained query expressions to produce this SQL to list the top five matches from the Adventure Works database:

    SELECT [t0].[ProductID], [t0].[Name], [t0].[ProductNumber], [t0].[MakeFlag], [t0].[FinishedGoodsFlag], [t0].[Color], [t0].[SafetyStockLevel], [t0].[ReorderPoint], [t0].[StandardCost], [t0].[ListPrice], [t0].[Size], [t0].[SizeUnitMeasureCode], [t0].[WeightUnitMeasureCode], [t0].[Weight], [t0].[DaysToManufacture], [t0].[ProductLine],
    [t0].[Class], [t0].[Style], [t0].[ProductSubcategoryID], [t0].[ProductModelID], [t0].[SellStartDate], [t0].[SellEndDate], [t0].[DiscontinuedDate], [t0].[rowguid], [t0].[ModifiedDate]
    FROM [Production].[Product] AS [t0]
    INNER JOIN (
        SELECT SUM(CONVERT(Int,[t1].[OrderQty])) AS [value], [t1].[ProductID]
        FROM [Sales].[SalesOrderDetail] AS [t1]
        WHERE (EXISTS(
            SELECT NULL AS [EMPTY]
            FROM [Sales].[SalesOrderHeader] AS [t2]
            INNER JOIN [Sales].[SalesOrderDetail] AS [t3] ON [t2].[SalesOrderID] = [t3].[SalesOrderID]
            WHERE ([t2].[SalesOrderID] = [t1].[SalesOrderID]) AND ([t3].[ProductID] = @p0)
            )) AND ([t1].[ProductID] <> @p1)
        GROUP BY [t1].[ProductID]
        ) AS [t4] ON [t0].[ProductID] = [t4].[ProductID]
    ORDER BY [t4].[value] DESC

    As Rob says:

    I can rewrite that query into a Sproc, lose 60% of the SQL, and be done with this whole thing in very short order. In addition, all of the LINQ statements amount to a lot of extra code just to build a SQL statement. However…

    If you break our your queries into steps and add some comments, like I did here, you understand a whole heck of a lot more what I, the stats wonk, am trying to do.  If you were to stumble accross a predictive Sproc in the DB, you would no doubt spend a whole lot of time trying to figure just WTF I was thinking.

    Added: 2/27/2008

    Bob Beauchemin Starts a Series About LINQ to SQL and Entity Framework

    Bob's MHO: LINQ to SQL and Entity Framework: Panacea or evil incarnate? Part 1 post of February 13, 2008 (which I missed), spells out the misgivings of a well-known SQL Server trainer (for SQLSkills), tuner and developer about the use of LINQ to SQL and Entity Framework in an enterprise IT environment. He lists the following six "worry points":

    1. LINQ to SQL and EF will proliferate dynamic SQL, and will almost surely produce suboptimal dynamic SQL, causing database performance problems and plan cache pollution. And dynamic SQL is evil to start with.
    2. LINQ to SQL and EF will encourage "SELECT * FROM..." style coding because you get back a nice, clean object this way instead of the less-useful anonymous type you receive by doing projection. This will also make most/all covering indexes useless.
    3. LINQ to SQL and EF will encourage "SELECT to middle-tier, then update/delete" rather than issuing direct SQL UPDATE/DELETE statements that are set-based.
    4. LINQ to SQL and EF will write code that gets too much or too little data at a time. This is a variation of #2. Too much data in one query is a waste. Too little data is also bad because it means extra database round-trips.
    5. LINQ to SQL and EF will discourage the use of stored procedures to return rowsets; returning rowsets in stored procedures is *thought to be* superior to returning them in dynamic SQL. In addition, the code generators will use a subset of T-SQL query constructs, that is, only the constructs that the LINQ or ESQL language supports, rather than the full power of the T-SQL query language.
    6. LINQ to SQL and EF queries will be "untunable" because, even if you discover a performance problem, you can't change the underlying API code to produce the exact SQL query that you want. There's too many layers of abstraction to change it

    The post above covers worry point #1. Chris Rock makes some interesting observations on proliferating query plans with parameterized queries and stored procedures in his LINQ TO SQL V 1.0 Hickups post of February 19, 2008.

    MHO: LINQ to SQL and Entity Framework: Panacea or evil incarnate? Part 2 of February 14, 2008 tackles worry point #2

    Added: 2/27/2008

    Joe Feser Unveils LINQ to NCover for Code-Coverage Analysis

    NCover is a commercial package for reporting the code coverage of unit tests for .NET projects. NCover has two versions: Professional (US$149) and Enterprise (US$299). The Enterprise edition provides detailed HTML reports and XML code-coverage data; Professional only outputs the XML data as Coverage.xml.

    Taking advantage of the XML code-coverage data requires sophisticated querying and sorting capabilities, so Joe Feser wrote the code for LINQ to NCover, which is available for download from a link in his Linq To NCover Part 2 post of February 26, 2008. LINQ to NCover processes queries, such as the following:

    c = CodeCoverage.Load(file);
    
    var retVal =from mod in c.Modules
                from cls in mod.Classes
                from method in cls.Methods
                where method.Name == ".ctor"
                select method;
    

    His earlier Linq To NCover Part 1 post of the same day provides additional background on the project and mentions that he went to work for Gnoso, Inc., NCover's publisher, in Taylors (a suburb of Greenville), SC.

    Added: 2/27/2008

    Matt Hidinger Discovers That the Entity Framework Won't Filter by Comparing Custom Classes

    In his Entity Framework Comparison Frustration: Explained post of February 26, 2008, Matt attempts to run the following code

    TorvusEntities entities = new TorvusEntities();
    
    // Pull my Account Entity from the database
    Account matt = entities.Accounts.First(a =&gt; a.AccountId == 10);
    
    // Attempt to get all Teams by a Team Owner
    var teams = from t in entities.Teams
                where t.Owner == matt
                select t;

    And receives an exception because:

    LINQ to Entities does not support using a user class as a constant. However, a property reference on a user class is considered a constant, and will be converted to a command tree constant expression and executed on the data store.

    From the "Comparison Expressions" topic of the LINQ to Entities Programming Guide.

    Matt's earlier post on the topic is ADO.NET Entity Framework Comparison Frustration.

    Julie Lerman Delivers a Hit .NET Rocks! Podcast About Entity Framework (and Admits to an Entity Framework Book in Progress)

    Don't miss it. You can listen to it here.

    She also comes clean in her Okay, so I'm writing a book post of February 27, 2008 that she's writing Programming Entity Framework for O'Reilly which she hopes will release in October. I'm really sorry she couldn't have a Newfi (Newfoundland dog) engraving on the cover because it had been used for a VBA book. :-(

    The title has a bit in common with David Sceppa's Programming the Microsoft® ADO.NET Entity Framework for Microsoft Press (due in July).

    Added: 2/27/2008

    Michael DeMond Adds an EDMX Code Generator Plug-in to EFContrib

    Michael's Plug-in Edmx Code Generator Released post of February 25, 2008 describes the code-generator plug-in he derived from the earlier Sample Edmx Code Generator by Sanjay Nagamangalam, an ADO.NET program manager. Michael's is the second project contributed to CodePlex's EFContrib project.

    The first comment to Sanjay's SampleEdmxCodeGenerator sources post of January 24, 2008 is the request for a plug-in version. It was nice of Michael to comply.

    Thanks to Julie Lerman for the heads-up.

    Added: 2/27/2008

    Alex James Completes His Teasers About Entity Teamwork Support for Associations with Payloads

    Alex observed in his first Associations with Payloads post of 2/24/2008, that Entity Framework (EF) automatically creates a many:many association instead of an entity for a table that consists entirely of two (or more) foreign key fields, but won't ordinarily do this if the association carries a payload, such as quantity. (See LINQ and Entity Framework Posts for 2/18/2008+).

    Next, his Associations with Payloads - part Deux post of 2/25/2008 concludes that a read-only association is the only way to circumvent the restriction without resorting (?) to a conventional entity.

    Finally (!), Alex's Associations with Payloads - closing the loop later the same day describes the seven hand-hewn modifications to the mapping files that are required to implement a read-only many:many association with a payload.

    Sounds to me like a lot of work to enable this LINQ to Entities query:

    var products = from o in ctx.Orders 
                   from p in o.Products 
                   where o.ID == 3435 
                   select p;
    
    

    Entity Framework Workaround for SQL Server 2008 Spatial Data Type

    Alex James points in his strangely-named All the power at your disposal post of February 25, 2008 to a SQL 2008 and spartial data post by 'Benys' in the ADO.NET (Pre-release) forum. Benys' post is a great example of developer self-reliance in the face of what appear to be poor odds.

    Benys asked if EF supports SQL Server 2008's spatial datatype. According to Danny Simmons, who should know:

    Unfortunately, no, the EF will not support spatial data from SQL Server 2008 in EF v1.  Spatial data in SS08 is a kind of user-defined-type, and while UDTs are something that the EF will support in future releases they do present some unique challenges and in the end were postponed to a later release.

    Benys solved the problem with a defining query and a partial class to return the spatial value as a binary data type.

    Beth Massi Demonstrates LINQ to SQL Data Validation with Partial Classes and Partial Methods

    Beth's Simple Validation with LINQ to SQL Classes post of February 25, 2008 describes in detail the steps required to:

    1. Implement the IDataErrorInfo interface
    2. Inherit the implementing class from partial EntityName classes
    3. Write the business rules to perform the validation
    4. Display the validation errors in the UI

    Beth's tutorials have become to VB projects what Scott Guthrie's are to C# and ASP.NET projects.

    Andrew Robinson: Set LINQ to SQL Text Box MaxLength with Reflection

    In his TextBox MaxLength from LINQ Meta Data post of February 24, 2008, Andrew shows you how to write an ExpressionBuilder to set the MaxLength properties of bound ASP.NET text box controls by reflection. He also includes the addition to the Web.config's <system.web><compilation> section to load the ExpressionBuilder.

    Wednesday, January 09, 2008

    LINQ and Entity Framework Posts for 1/7/2008+

    Note: This post is updated daily or more often, depending on availability of articles. As of this issue, the publication date will be reset after adding significant new posts.

    Update 1/9/2008: Date (year) errors fixed.

    The VB Team: Writing UNION, TOP and Subqueries in LINQ

    The Converting SQL to LINQ, Part 7: UNION, TOP, Subqueries (Bill Horst) post of January 8, 2008 covers use of LINQ Union, Intersect, Except, Take, TakeWhile, and Skip Standard Query Operators in VB 9.0 query expressions.

    Added: January 9, 2008

    Marcello Lopez Ruiz Clarifies ADO.NET Data Services' URI Format

    Marcello's Updates to URL syntax for December CTP of ADO.NET Data Services post of January 8, 2008 advises that the current Astoria CTP uses only the compact URI syntax. Compact URI syntax uses the resource set name followed by one or more comma-separated, single-quoted identifiers enclosed in parenthesis as in: /Customers('ALFKI').

    The long-form syntax, described in Mike Flasko and Pablo Castro's URI Format - Part 1 - Addressing resources using URI path segments post of September 21, 2007 in the Astoria Project Team blog, was not implemented, presumably because the team abandoned the Web3S wire format in favor of JSON, ATOM (and hopefully POX) formats only.

    Added: January 9, 2008

    Julie Lerman: SQL Server CE Provider Coming for Entity Framework December CPM

    Julie's SQL Server CE compatibility with EF Beta 3 in a few weeks... post of January 8 quotes the EF team's Jaroslaw Kowalski with the timetable for an upgraded SSCE Entity Framework data provider.

    Added: January 8, 2008

    Dare Obasanjo Compares LINQ with Python for List Processing

    Dare writes a very terse C# LINQ to Objects query to find and display anagrams within 1,219 of the most popular male names in the U.S. in 97 milliseconds or less. Doing the same for 4,275 female names takes about 557 ms.

    Added: January 8, 2008

    Scott Guthrie Starts Dynamic LINQ Query Series

    Scott kicks off his new Dynamic LINQ series with Dynamic LINQ (Part 1: Using the LINQ Dynamic Query Library) post of January 7, 2008 (earlier than usual—11:03 PM) that makes use of the unpublicized LINQ Dynamic Query Library that's included in the C# and VB samples packages you can download from here (C#) or here (VB). Downloads require agreement to the new Microsoft Public License (Ms-PL).

    Some bloggers refer to LINQ queries in which you substitute string or numerica variables for literal constants in the query expression as "dynamic." However, the LINQ Dynamic Query Library goes a big step further by letting you substitute composable strings for Standard Query Operator arguments in queries that use method call syntax. The library generates expression trees by parsing the strings. Of course, You exchange type safety and IntelliSense for flexibility when you employ this technique.

    Scott offers VB and C# ASP.NET Web site samples, and points to the Albahari brothers' Dynamically Composing Expression Predicates post that describes their PredicateBuilder class. PredicateBuilder is part of their LINQKit productivivity kit for LINQ to SQL, which every LINQ partisan should have.

    Update: In response to a comment, Scott adds the following advice:

    LINQ to SQL uses type-safe data model classes, you are protected from SQL Injection attacks by default.  LINQ to SQL will automatically encode the values based on the underlying data type.

    BTW - you can use the Where() extension method either like so:

       .Where(String.Format("CategoryID={0}" & Request.QueryString["id"])

    Or:

       .Where(String.Format("CategoryID=@0", Request.QueryString["id"])

    The second option allows you to specify any parameter markers you want in the query, and then in[j]ect the values as params that you pass separately.

    Be sure to read the comments and Scott's replies.

    Added: January 8, 2008

    Stefan Cruysberghs Examines Dynamic LINQ Where and OrderBy Clauses

    Apropos Scott's Dynamic LINQ queries post, Belgian developer Stefan Cruysberghs' .NET - LINQ to SQL - part 4 article of January 7, 2008 goes into the details of

    • Anonymous functions and IEnumerable
    • Lambda expression trees and IQueryable
    • PredicateBuilder class and combining expressions
    • Predicate library

    for creating dynamic Where and OrderBy clauses.

    The article also includes links to his three preceding LINQ-related Web pages. Click here for a complete list of Stefan's articles in English.

    Update 1/9/2008: Stefan's recent articles cover a wide range of topics of interest to VS developers, including detailed data on the performance improvement you can expect from PLINQ. His English .NET RSS feed includes brief abstracts.

    Added: January 8, 2008

    LINQ to XML: Grouping and Aggregation Gotchas, Part I

    LINQ to XML is a candidate to replace XQuery for grouping elements, transforming Infosets and aggregating numerical data. It also can supplant XPath for navigation and XSLT for grouping and transformation. Aggregating elements or element groups and generating sum, average, minimium and maximum values is one of the most common uses for XQuery, XPath and XSLT.

    However, non-trivial LINQ to XML examples that demonstrate element grouping and numerical aggregation are few and far between. This LINQ to XML: Grouping and Aggregation Gotchas, Part I post of January 7, 2008 describes two Microsoft grouping samples that don't behave as expected.

    C# Team Posts Custom LINQ to TerraServer Implemetation

    Charlie Calvert's TerraServer Sample: A LINQ Provider post of January 6,2008 announces the arrival of yet another custom (not third-party in this case) LINQ implementation: LINQ to Terra Server.

    Here's the project's description from the project's ReadMe.htm file:

    This sample is a custom LINQ provider for the TerraServer-USA Web service. It also contains a sample client application that uses the custom LINQ provider to query the Web service for geographical data.

    The TerraServer-USA Web service exposes a method that returns information about locations in the United States when the method is given part or all of a location name. This method, which is named GetPlaceList, is the method that the LINQ provider calls to obtain the data that the LINQ query is run against. The provider uses Windows Communication Foundation (WCF) to communicate with the Web service. For more information about the TerraServer-USA Web service, see Overview of the TerraServer-USA Web Services.

    A LINQ provider that implements the System.Linq.IQueryable<T> interface, such as this one, enables LINQ queries to be written against the data source that the provider connects to. A provider may execute the query functionality on the data itself, or it may translate the LINQ query into a query language that is appropriate for the data source that it connects to. This provider obtains raw data from the Web service and then modifies the original query in such a way that LINQ to Objects handles the query execution.

    And here's sample output from the console:

    States that have a place named "Redmond":
    Washington
    Colorado
    Oregon
    Utah
    West Virginia
    Pennsylvania
    
    Number of places whose names start with "Lond": 29
    
    Places, ordered by state, whose name is either "Johannesburg", "Yachats", or "Seattle":
    { Name = Johannesburg, State = California }
    { Name = Johannesburg, State = Michigan }
    { Name = Yachats, State = Oregon }
    { Name = Seattle, State = Washington }
    { Name = Johannesburg, State = Wisconsin }

    MSDN's new Walkthrough: Creating an IQueryable LINQ Provider article shows you how to create the provider and client from scratch. (The link in the ReadMe.htm is incorrect.)

    The LINQ to TerraServer code is part of a set of C# samples that you can download from here (requires agreement to the new Microsoft Public License (Ms-PL). 

    Note: A few years ago, I wrote a graphic Web service front end to TerraServer in VB 2003. "Build Real-Time Web Images" article in the August 2004 issue of Visual Studio Magazine described a Visual Basic .NET 2003 graphic consumer of TerraService.net Web Services, as well as Microsoft MapPoint services. You can download the source code for the project here.

    David Hayden Continues His Dynamic Data Series with Metadata Providers Tutorial

    David says in ASP.NET Dynamic Data Tutorial - BuddyMetadataProvider and Custom Metadata Providers of January 6, 2008:

    This is my 5th tutorial on the new ASP.NET Dynamic Data that ships with the ASP.NET 3.5 Extensions CTP. ASP.NET Dynamic Data is an alternative to code generation in helping one build database-driven web applications in a more productive manner. ...

    If you don't like adding metadata to partial classes via attributes, the MVCToolkit contains a couple of custom metadata providers that you can use as a vehicle for adding metadata to your Dynamic Data Applications in different ways:

    • BuddyMetadataProvider
    • XmlMetadataProvider

    And goes on to explain how to use both.

    Ruurd Boeke Demonstrates Entity Framework's Table Per Type Inheritance

    Catch-up: Ruurd's How To: Table per type inheritance with Entity Framework post of January 2, 2008 provides an illustrated walkthrough for implementing TPT inheritance with the classic three tables and classes: Person and related/derived Employee, and Customer entities.

    Update January 9, 2008: Following are links to some of Ruurd's earlier Entity Framework posts:

    Update January 10, 2008: Fixed error in spelling of Ruurd. Sorry about that.

    Scott Hanselman Endorses LINQ to Mock (Moq)

    From the "How Did I Miss This?" department: Scott's Moq: Linq, Lambdas and Predicates applied to Mock Objects of December 19, 2007 starts with:

    Kzu and friends have a new pet project called Moq, which may be the coolest derivative open source project name ever.

    And ends with:

    Slick. Moq is definitely a project to watch.

    In between, Scott compares NMock, RhinoMock, TypeMock and Moq (a.k.a., LINQ to Mock for provider naming consistency.)

    The "Daniel Cazzulino and Juan Wajnerman Create LINQ to Mock (Objects)" topic of LINQ and Entity Framework Posts for 12/17/2007+ has more details on the release of LINQ to Mock.