Tuesday, December 11, 2007

Link and Entity Framework Posts for 12/10/2007+

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

Julie Lerman Explains How to Embed Schema Files in the EF's Assembly

The Entity Framework's EDM Designer connects to a single .edmx file in design mode. By default, building an EF project copies parts of the .edmx file to individual .ssdl, .msl, and .csdl files in the project's ...\bin\debug or ...\bin\release folder.

As Julie explains in her Embedding EDM schema files in Entity Framework Beta 3 post of December 14, 2007, you can set the .edmx file's MetadataArtifactProcessing property to Embed in Output Assembly to create a self-contained .exe or .dll that includes the three schema files as resources. She points out a bug in Beta 3 that requires you to build the project with Copy to Output selected before you change the preceding property value.

Added: 12/15/2007

Matt Manley Explores Late Binding of Visual Basic Lambda Functions

VB 9.0 lambda functions are more flexible than C# 3.0's because the Microsoft.VisualBasic.CompilerServices.Operators class detects mathematical operators and tests to see if they apply to the functions argument(s). If not, the compiler uses reflection with the Microsoft.VisualBasic.CompilerServices.NewLateBinding class, as it does for arguments of object types. There's more detail about this topic in Matt's Visual Basic .NET Late Binding Explored post of December 15, 2007.

Added: 12/15/2007

David Ebbo Posts Dynamic Data FAQs

Apparently, Scott Guthrie's Dynamic Data tutorial post (see below) generated a lot of interest in Dynamic Data (formerly code-named "Oryx"), so David published some FAQs that shine more light on the features future direction in his Answers to frequently asked ASP.NET Dynamic Data questions post of December 14, 2007.

Added: 12/14/2007

Zlatko Michailov Attacks the SQL Server Len() Function's Ambiguities

In his SQL Server’s LEN() Function of December 14, 2007, Zlatko notes that SQL Server's LEN() function doesn't count trailing spaces.

Added: 12/14/2007

Zlatko Michailov's Sales Pitch for the Entity Framework

Zlatko's December 14, 2007 Entity Framework and Object/Relational Mapping post makes a fervent plea to developers not to think of EF as an O/RM tool but a development platform. Here's his core argument:

Entity Framework takes a completely different approach – it creates a development platform in the space between database and objects. That is the Conceptual space. It’s a virtual space, unconstrained from objects- and database legacy. That allows Entity Framework to support static modeling capabilities with type hierarchies and containment as well as explicit, navigatable, relationships. What’s similar to O/R Mappers, is the mapping. However, it’s not a single, object-to-store mapping bridge, but two separate bridges – object-to-conceptual and conceptual-to-store. (The object-to-conceptual mapping is implicit for version 1.)

I wonder what the "NHibernate Mafia" have to say about this claim and EF's persistence ignorance.

Added: 12/14/2007

Amazon Announces Beta of SimpleDB Web Services in the Cloud

Amazon announced in their Amazon SimpleDB™- Limited Beta post of December 14, 2007 that Amazon Web Services, LLC would start selling in a few weeks pay-per-GB space on and connections to a non-relational, attribute-based database service that's integrated with Amazon Simple Storage Service (Amazon S3) and Amazon Elastic Compute Cloud (Amazon EC2). The service supports REST and SOAP request/response operations.

Read more at Amazon Announces Beta of SimpleDB Web Services in the Cloud.

Added: 12/14/2007

Beth Massi Interviews Aver Aharoni about LINQ to XML Literals and Namespaces

In this 23:47 Channel9 interview, XML Literals Performance and Namespaces Explained, Beth Massi watches VB Team program manager Aver Aharoni ...

... as he dives into LINQ to XML and XML Literals in Visual Basic 9 and explains namespace bubbling and the performance gains you may see using XML Literals. This is a good interview to pay attention to if you are struggling with how XML namespaces work in Visual Basic.

This topic was added before Beth updated her blog.

Added: 12/14/2007

Rafik Robeal Describes SyncServices for ADO.NET 2.0's DbPeerSyncProvider

In his What’s new in Sync Services for ADO.NET 2.0? post of December 13, 2007, Rafik provides an overview of the new DbPeerSyncProvider, which is part of the Microsoft Sync Framework CTP1 Refresh. Rafik says its architecture uses the same programming model as the DbServerSyncProvider.

Added: 12/14/2007

Pro LINQ: Language Integrated Query in C# 2008 From Apress

Joseph C. Rattz, Jr.'s book about LINQ is now available from APress in paper and eBook formats. Links to the ToC and Chapter 1 are here.

Added: 12/14/2007

Scott Guthrie's Dynamic Data Tutorial Parallels David Ebbo's Video

Scott's New ASP.NET Dynamic Data Support post of December 14, 2007 is a detailed tutorial for creating your first scaffolded ASP.NET 3.5 project from a LINQ to SQL data source. The tutorial follows the steps outlined in David Ebbo's video segment at Dynamic Data screencast is now available! (see below for description).

Added: 12/14/2007

Noam Ben-Ami Demonstrates the EDM Designer's New Stored Procedure Support

This 12-minute video clip, which Sanjay Nagamangalam describes in his December 13, 2007 Entity Data Model Designer Video - CTP 2 post covers the Entity Framework's EDM Designer CTP 2 and its new support for mapping UPDATEs, INSERTs, and DELETEs of entity types to stored procedures. CTP 2 also lets you map SELECT stored procs to return primitive types and entity type collections. The final segment covers the new "Update Model from Database" feature that synchronizes the EDM to database changes.

Added: 12/14/2007

Christian Weyer Shows You How to Self-Host ADO.NET Data Services

The QuickStart examples use ASP.NET/IIS to host ADO.NET Data Services (Astoria), but most developers prefer to use WCF's new self-hosting feature provided by the WebServiceHost with the WebHttpBinding class that supports Plain Old XML (POX) instead of SOAP messaging.

Christian's Self-Hosting Your ADO.NET Data Services ("Astoria") Services post of December 11, 2007 shows you how to specify the [ServiceContract] and [OperationsContract] attributes for the IRequestHandler interface, add the required section to the app.config file for a console project, and invoke the WebServiceHost(typeof(WebDataService).Open() method.

You can expect some concrete examples from Mike Taulty shortly.

Added: 12/14/2007

Reading and Writing SQL Server 2008 FileStreams Videos by Mike Taulty

Mike posted Video: SQL 2008 and FileStream (writing data) and Video: SQL 2008 and FileStream (reading data) on December 13, 2007. As usual, the videos are brief, to the point, and capture the essence of what in this case is relatively complex subject matter. Working with FileStreams requires function calls to unmanaged code.

Added: 12/14/2007

Latest VB Cookbook Applies Group Joins and Aggregates to DataSets

LINQ Cookbook, Recipe 11: Desktop Search Statistics (Doug Rothaus) of December 13, 2007 uses Windows Desktop Search's OLE DB data provider (Search.CollatorDSO.1) to fill a DataSet which LINQ to DataSets queries to deliver a generic List of items and count of each item type for Documents, E-Mail or Images.

Added: 12/14/2007

Marcin Dobosz Explains Dynamic Data's Custom Metadata Providers

According to Marcin's Adding custom metadata providers in ASP.NET 3.5 Extensions Preview post of December 10, 2007, the three special metadata attributes described in the How to: Add Validation to the Data Model using Attributes online help page are for Dynamic Data's initial implementation only.

The MVC Toolkit provides an early MVC implementation for future Dynamic Data versions that will deliver:

  • A pluggable metadata model based on providers.
  • New metadata attributes that can be declared on the properties of a special metadata "buddy" class.
  • An alternative reference provider implementation based on XML files.

His post included brief descriptions of these features. He also notes that the initial Dynamic Release supports only LINQ to SQL as its data source; future releases also will accommodate LINQ to Entities.

Marcin is the program manager for the ASP.NET 3.5 Extensions' Dynamic Data feature and Astoria.

Note: The ASP.NET Dynamic Data forum is at http://forums.asp.net/1145.aspx.

Added: 12/13/2007

Danny Simmons: Use KnownTypes to Deserialize Polymorphic Entities

Serializing entities (even without the ObjectContext) is a can of worms, as demonstrated by my Serializing Object Graphs Without and With References post of 11/21,2007. Danny points out in his DataContract Serialization, Entity Framework and "Known Types" post of December 12, 2007 that you must add a list of subtype names of derived types to the [ServiceKnownType("GetKnownType", GetType(ObjectContextTypeName))].

Danny's modification to the GetKnownType helper function replaces manually typed strings with a list of ServiceKnownTypes from the ObjectItemCollection by reflection. Nice!

Added: 12/13/2007

David Ebbo Delivers a Dynamic Data Demo as a 00:17 Screen Cast

David's December 12, 2007 Dynamic Data screencast is now available! post has a link to the segment, which demonstrates most of the features of the new Dynamic Data scaffolding from the ASP.NET 3.5 Extensions:

  • Creating a Dynamic Data project
  • Creating a LINQ to SQL model
  • Running the scaffolded version of a Dynamic Data project
  • Customizing data validation
  • Customizing UI presentation
  • Adding metadata to the model
  • Writing custom pages in place of the scaffolded ones

    David is a developer for the ASP.NET 3.5 Extensions' Dynamic Data feature.

    (Topic list courtesy of Marcin Dobosz, see above)

    Added: 12/13/2007

    Zlatko Michailov's eSQLBlast Program Posted on CodePlex

    Source code for Zlatko Michailov's eSQLBlast program is available for download from the ADO.NET Samples Page on CodePlex. Zlatko says the following in his eSqlBlast – The Ultimate Tool for Writing Entity SQL Queries post of December 12, 2007:

    Microsoft.Samples.Data.eSqlBlast, briefly eSqlBlast, is a suite of tools and libraries that complements Entity Framework. It aids authoring, executing, and visualizing ad-hoc Entity SQL queries against arbitrary EDM models. The tools of the eSqlBlast suite may be used interactively, from the command line, or embedded in other programs. The eSqlBlast suite also contains XSL transformation scripts for rendering CSDL and its own raw XML format.

    Added: 12/13/2007

    Eric White Continues his LINQ to OOXML Series with the WordProcessingML Class

    Eric's The WordprocessingML Class: A refinement of the approach of using LINQ to XML to access Open XML post of December 13, 2007 briefly describes the additional functionality the class brings to Office Open XML, includes a sample LINQ query and provides a link to a listing of the full WordprocessingML class.

    Added: 12/13/2007

    Julie Lerman Explains How to Use the ObjectStateManager.GetObjectStateEntries Method

    Julie's December 13, 2007 EF ObjectStateManager.GetObjectStateEntries (plural) post explains how she uses the method in conjunction with entity updates, with source code for adding a new and modifying an existing entity.

    Added: 12/13/2007

    Bill Horst Translates T-SQL Scalar and Aggregate Functions to LINQ

    In his Converting SQL to LINQ, Part 4: Functions (Bill Horst) post of December 12, 2007, Bill continues his series with brief descriptions of how VB 9.0 LINQ scalar and aggregate function syntax differs from that of T-SQL. LINQ aggregate functions commonly use group join or Group Join operators but Bill's VB LINQ example for Sum() uses a simple Aggregate ... Into expression.

    Added: 12/12/2007

    Guy Burstein Starts ASP.NET Web Data Services Series

    Guy's ADO.Net Data Services Part 1 - Building a Simple Web Data Service post of December 12, 2007 starts a series devoted to creating and consuming sample Astoria data from a blog database that you create from a script in an earlier post.

    Like Andy Conrad, Guy uses LINQ to SQL instead of the Entity Framework as the data source. I have the feeling this substitution will become universal, at least until RDBMS vendors other than Microsoft deliver EntityClient data providers.

    Julie Lerman comments on the SQL-Server-only issue in her ADO.NET DataServices and ANY IQueryable post of December 12, 2007.

    Added: 12/12/2007; Updated 12/14/2007

    Pete Weissbrod Compares LINQ to SQL to NHibernate

    Pete's company wanted to know if LINQ to SQL would be a better object/relational mapping (O/RM) tool than NHibernate, which most developers consider the "industry standard." So Pete is sharing his findings in a series of posts, the first of which is LINQ to SQL vs NHibernate Part 1: What do they have in common? of December 9, 2007. This post provides a broad-brush overview of:

    • Mapping syntax
    • Persistent object lifecycles
    • Version management
    • Adjustable fetching schemes
    • Concurrency concerns
    • Customer database objects
    • Code generators

    Pete promises to compare performance, flexibility, and usability "in the next few days."

    Added: 12/12/2007

    ASP.NET Data Services Wow Dare Obasanjo

    Dare says in his December 11, 2007 ADO.NET Data Services (Astoria) Transforms SQL Server into an Atom Store post:

    Normally, announcements related to ASP.NET would not interest me except this time [there] is an interesting item in the list of technologies being released. ...

    Wow. It looks like Astoria has quickly moved from being an experimental project to see what it would [be] like to place RESTful interfaces on top of SQL Server database to being very close to shipping a production version. ... [Emphasis added.]

    This is s[l]ick. With Astoria I can expose my relational database or even a local just an XML file using a RESTful interface that utilizes the Atom Publishing Protocol or JSON. I am somewhat amused that one of the options is placing a RESTful interface over a SOAP Web Service. My, how times have changed…

    It is pretty cool that Microsoft is the first major database vendor to bring the dream of the Atom store to fruition. I also like that one of the side effects of this is that there is now an AtomPub client library for .NET Framework.

    Dare also likes Andy Conrad's LINQ to REST implementation (see below.)

    Eric White Explains How to Use LINQ to XML with Office Open XML

    In his swansong to his current job of documenting XML technologies (mostly LINQ to XML), Eric's Using LINQ to XML with OpenXML Documents post of December 11, 2007 has provides links to the four contemporaneous posts:

    Each post contains non-trivial sample code and most have relatively simple LINQ queries.

    Eric's new job is technical evangelist for Office Open XML (OOXML).

    ASP.NET 3.5 Extensions Preview Released

    This December 10, 2007 post details my initial installation and test drive of the ASP.NET 3.5 Extensions Preview's Dynamic Data scaffolding and Data Services (Astoria).

    I expected the ASP.NET Dynamic Data feature to be derived from SubSonic based on Rob Conery's contention that SubSonic will be the "Convention-Driven Toolset for Microsoft’s New MVC Framework" for ASP.NET in a length post after joining Microsoft's ASP.NET team, but it didn't happen. Dynamic Data's default scaffolding is based on a master-page design and is similar to Polita Paulus's Blinq project, which wasn't updated for ASP.NET 3.5. The initial data source is LINQ to SQL and the LinqDataSource control; future support for LINQ to Entities is promised.

    There's hope for the SubSonic-based scaffolding, however. Rob left this comment on my ASP.NET 3.5 Extensions Preview Released post of December 10, 2007:

    >>The question here is: "What happened to the SubSonic-based "convention-driven" scaffolding?"<<

    It's coming :). Just need a week or 2 here.

    I was able to get a C# ASP.NET Data Services data source up and running by following the QuickStart instructions, but two attempts to create a source with VB failed. I'll test Web and WinForm clients later this week.

    Click here for more details and screen captures.

    Andrew Conrad Starts Series of Articles About LINQ to REST

    Astoria technical lead Andy Conrad posted on December 10, 2007 the first of a series of articles about LINQ to REST (a.k.a., LINQ to Astoria and LINQ to ASP.NET Data Services) that will cover, in his words:

      1. How to set up an Astoria Data Service which can be used for remote execution of Linq queries.
      2. Dive deep into the Astoria Client API's Linq support including a detailed description of how Linq queries are translated to URIs.
      3. How to make the Astoria Data Service updateable so the results of the Linq queries can be remotely modified and persisted.

    The first post, Linq to REST, shows you how to set up a data service based on a LINQ to SQL (not an Entity Framework) data source and a simple console client to demonstrate the Astoria client library, Microsoft.Data.WebClient.dll, that translates LINQ queries to Astoria's URI scheme.

    In conclusion, Andy promises:

    In future posts, I will explain how that worked.  What all the Linq capabilities that are supported.  And what one can do with the objects once they are materialized.

    Based on the ease of use and other benefits of LINQ to SQL as the data source for Astoria, it's my conclusion that developers who favor SQL Server will use LINQ to SQL instead of the Entity Framework for projects that aren't required to support complex inheritance models.

    ADO.NET Data Services Validation and Access Control Features

    Mike Flasko explains in his ADO.NET Data Services Dec2007 CTP - Validation and Access Control post of December 10, 2007 that Astoria resources are locked down by default.

    He also notes that Astoria depends on the Windows Communication Framework (WCF) for authentication, and then goes on to describe the ResourceContainerRights enumeration for the configuration.SetResourceContainerAccessRule method and how to add a query interceptor for ad hoc access control. Change interceptors hook into update operations, which might also require access control.

    Charlie Calvert Revisits LINQ to SQL's DataContext

    Charlie explains LINQ to SQL's approach to object/relational mapping (O/RM) and how the DataContext object works in his December 10, 2007 Understanding the DataContext post.

    This must be at least the 500th iteration of this topic by bloggers.

    Danny Simmons Explains How to Recreate an Object Graph's Associations

    In his December 8, 2007 Computing an Original Value Graph post, Danny continues his quest to recreate complete Entity Framework object graphs from information stored in the ObjectStateManager and RelationshipManager. Danny's previous Creating an original value object from the separate values stored in the ObjectStateManager of November 11, 2007 (updated 12/3/2007) and Concepts Part II: Relationships of December 2, 2007 provide the background for regenerating references to associated entities.

    Regenerating the references for entity associations requires several helper methods and a recursive SetRelationships function. Much of the complexity is due to missing foreign key values for many:1 and 1:many relationships. If your base entities include foreign key values, such as LINQ to SQL provides, you can generate references by relatively simple LINQ queries. (I appear to have lost my fight for an option to make foreign key values visible.) This is a major consideration when serializing entities to XML for transport across process boundaries.

    Danny ends with this commentary on serialization:

    One interesting related question we are debating internally is the granularity users would most use when tra[n]sporting entities with this additional information. You could imagine, for instance, serializing a single cache entry in order to transport an entity along with its state, set of modified properties and original values. At the other extreme, you might just serialize an entire object cache which would bring along an arbitrary set of entities and could be an efficient way to transport multiple entities at once (including relationships between them, etc.). In the middle somewhere is the ability to specify a graph of related entities and bring them (and their tracking information), but naturally there are a number of interesting issues that would have to be worked out to enable that scenario (like how to specify what part of the graph to serialize, etc.).

    The real issue is dealing with cyclic associations when serializing objects with many:1 and 1:many relationships, as I discussed in my Serializing Object Graphs Without and With References post of November 21, 2007 (updated 11/25/2007). The LINQ to SQL group punted by sticking with the DataContractSerializer and now has no "out-of-the box multi-tier story." Hopefully this fate won't befall Entity Framework v 1.0.

    Entity Framework Beta 2 to Beta 3 Breaking Changes

    The ADO.NET Team's Breaking Changes- Entity Framework Beta 3 post of December 6, 2007 lists five breaking changes to the Entity Data Model, two for Entity Services, one for LINQ to Entities, 12 for Object services and 2 for Tools.

    (This post was omitted from last week's list. )