Category Archives: Data Access

Upcoming DevConnections talks: Silverlight Annotation, Ink on the Web, Entity Framework and LINQ

The fall DevConnections is coming up in another 10 days (Nov 5-9) in Las vegas.

It looks like they will have about 5,000 attendees again, like last year which is amazing.

I will be doing a variety of talks.

One that i’m especially looking forward to will be teaming up with John Sudds from the Internet Explorer team to present on embedding Ink-Enabled Win Forms controls into ASP.NET 2.0 pages. This will be part of the Microsoft Day session for Mobile Connections. John brings a new level of expertise to the work I have done in this area and solved some problems I was never able to get around. John will be the demo god in this session and i get to do my favorite thing: Talk!

I will also be doing a talk about Annotating with Silverlight as part of the Mobile COnnections show. Don’t let this fool you. Annotating in Silverlight, while best on a tabletpc, also works  nicely on regular pcs and on Macs – anywhere that you can run Silverlight. If you haven’t seen the various test apps that I have deployed on the web, you can check them out here: the Step-by-Step series and the database persistence application.

In the ASPConnections show, I will be doing a session on ASP.NET DataBinding with LINQ which will explore many flavors of LINQ, not just LINQ to SQL.

And then there is the Data Access track in which I will be presenting and advanced talk on Entity Framework – Real World Entity Framework with a focus on multi-tier apps. John Papa will precede this talk with two intro type talks.

Lastly, I will be a presenting a post-conference 1/2 day (9am-12pm) workshop on guidance for accessing data in .NET 3.5. We now have ADO.NET, LINQ to SQL and three ways to query data in Entity Framework. There will be a number of entity framework and LINQ to SQL talks during the main conference, so this session is aimed at comparing and contrasting them and providing guidance on when it makes sense to use each one.

There’s still room to sign up! http://www.devconnections.com   

EF EntityClient for performance

Earlier this week, I wrote a post discussing when I would choose querying an data through an Entity Data Model using LINQ to Entities vs. Object services + Entity SQL vs. EntityClient + Entity SQL.

One of the advantages I pointed out about using EntityClient is that it returns datareaders and does not attempt to turn the returned data into objects. In re-reading Zlatko Michailov’s EntityClient post from earlier this year, I realize that I didn’t highlight one of the most important reasons about being able to return datareaders, in case it isn’t obvious: Performance. But note that this is for reading only.

If you do not need the Entity objects materialized by object services and do not need the other benefits of object services (e.g. change tracking and DML) and just want to get your hands on the data, using Entity Client will get it to you the most quickly. While this can also be done with ADO.NET, EntityCLient gives you the benefit of querying the conceptual model rather than directly against the database schema.

Lots of Entity Framework at DevConnections Nov 5-8, Las Vegas

In his “Microsoft’s Data Access Strategy” blog post, Mike Pizzo, who is an architect for the overall Data Programmability team at Microsoft says:

“The Entity Data Platform is a multi-release vision, with future versions of reporting tools, replication, data definition, security, etc. all being built around a common Entity Data Model. 

Within the .NET Framework, the ADO.NET Entity Framework is integral to this vision.”

The first release of the Entity Framework will arrive in the first half of next year. Many companies are looking at it right now as they consider their software’s architecture and how EF fits in. I know this because I have actually been working with some of them as a mentor.

You can get a big leg up for planning ahead and learning now on Entity Framework at DevConnections next month in Las Vegas.

As part of the special Data Access track (which features an all-star cast of data gurus: Bill Vaughn, Alex Homer, Dave Sussman, John Papa, Dino Esposito, Don Kiely, Kathleen Dollard, and me!) there will be seven Entity Framework sessions and additionally a 1/2 day workshop at the end of the conference which will provide guidance about when to use Entity Framework (and which of it’s 3 methods of querying) compared to when to use LINQ to SQL or just plain old ADO.NET. (Note that you need to sign up specificially for the workshop which costs an additional $199).

Danny Simmons, from the EF team, is not speaking but will be there for the sake of geeking out and has said on his blog:  If you are going, and would like to get together and chat about the EF, ADO.Net, OR/M in general, Domain Driven Design, Agile, or other geeky topics, then put a comment here or send me some email, and we’ll find a way to get together.

On “Microsoft Day”, the first day of the conference, there are three sessions related to Entity Framework by members of the team

  • VDM302: ADO.NET Entity Framework Designers
    Sanjay Nagamangalam
    The ADO.NET Entity Framework (EF) enables compelling Object-Relational Mapping scenarios. This session is focused on developer walkthroughs and demonstrates new designer capabilities in Visual Studio that enable developers to visually design their EF data access layer and map it to a relational database. We also discuss how EF tools and designers help enhance developer productivity while alleviating typical developer pain points during iterative development. It is recommended that you attend “Data Modeling and Application Development with the ADO.NET Entity Framework” before this session.
  • VDM304: Data Modeling and Application Development with the ADO.NET Entity Framework and LINQ over Entities
    Tim Scudder
    Object Relational Mapping technologies have long been used as the infrastructure for the Data Access Components within an application’s architecture. The introduction of the Entity Data Model will make available a first class data model with which application architects can define their domain model and build out their data access layer. With ADO.NET and the Entity Data Model, architects have a number of choices. They can work with Entities with the familiar DataReader and DbCommand abstractions (using the new EntityClient data provider) or they could use generated classes as persistent objects (with LINQ and Entity SQL-based API’s). This session shall discuss the different ways in which one can use ADO.NET and the Entity Data Model within one’s application architecture. The discussion shall include different deployment models and the role that the Entity Framework can play within them. In addition, this session will discuss LINQ over Entities. Most .NET database applications use ADO.NET to access and manipulate data, and most of them have a data-access layer built on top of ADO.NET to abstract out many of the details related to data-access that can get in the way of business logic. We’ll discuss how the system supports conceptual modeling and how great integration with LINQ (language-integrated query) brings new levels of productivity to the data-access development space.
  • VDM303: Project Astoria: Data Services for the Web
    Mike Flasko
    The new wave of Web applications are built on technologies such as AJAX and Microsoft Silverlight, which enable developers to build better, richer user experiences. These technologies bring a shift in how applications are organized, including a stronger separation of presentation from data. The goal of Microsoft code name “Astoria” is to enable applications to expose data as a data service that can be consumed by Web clients within a corporate network and across the Internet. The data service is reachable over HTTP, and URIs are used to identify the various pieces of information available through the service. Interactions with the data service happens in terms of HTTP verbs, such as GET, POST, PUT, and DELETE, and the data exchanged in those interactions is represented in simple formats, such as XML and JSON.

During the main conference, there are four sessions on Entity Framework and a number of the other Data Access sessions will touch on it as well.

  • VDA305: Implementing the Entity Framework
    John Papa
    You can use the Entity Framework to architect applications against a conceptual model that is mapped to the logic model. This session will explore the different XML files that map the objects to the database schema and show how to modify them when needed. I will explain how you can design an object model with the Entity Framework using both the Entity Data Model Wizard as well as by manually editing the XML files. I will demonstrate how to implement inheritance and how to merge multiple entities within a conceptual model as well as how to take advantage of features such as conditions in the mapping layer. This session will demonstrate how to interact with the conceptual model using EntityClient, Entity SQL, and LINQ to Entities to perform queries and make updates to a database.
  • VDA303: Unraveling the Entity Framework
    John Papa
    You can use the Entity Framework to architect applications against a conceptual model that is mapped to the logic model. The Entity Framework has many components including EntityClient, Entity SQL, Object Services, the Entity Data Model, and LINQ to Entities. This session will discuss the architecture of the Entity Framework and explain the roles of each of its different components. I will also demonstrate how to write queries using the different options as well as how to evaluate which options within Object Services to use or if to use the EntityClient provider directly.
  • VDA307: Real-World Entity Framework
    Julia Lerman
    After learning the basics of the Entity Framework, it’s time to see how to implement entities in more complex applications. The Entity Framework’s Object Services provide functionality for persisting objects as well as moving them across machine boundaries. Come to this session to learn patterns that can be used across tiers in Web applications, WCF services and clients, or smart client applications.
  • VDA308: ADO.NET Metadata and Code Generation
    Kathleen Dollard
    LINQ to SQL and Entity Frameworks include code generators. You’ll learn about this technology under the hood and the new metadata strategies these technologies use. This metadata is interesting because it represents some of the first mainstream standards for mapping metadata. If you’re currently using code generation, you’ll want to learn how to leverage these metadata sets to enhance your code generation. If you’re using or considering the ADO.NET technologies, you’ll want to assess your back up strategy if you later need to step outside the box and make a change to how these technologies work. If you elect to do your own code generation, you’ll see the benefits of folding in additional metadata that solve additional problems like automated name morphing. You’ll also see how to leverage patterns in your raw metadata to generate and possibly help maintain the mappings between your database and business objects. This session is technology agnostic and applicable to XSLT, CodeSmith and CodeDOM generation.

And the post-conference workshop

  • VPS201: ADO.NET 3.5 Data Access Guidance (9:00AM – 12:00PM)
    Add’l Fee $199.00

    Julia Lerman
    ADO.NET 3.5’s Entity Framework presents us with a slew of new options for accessing data which you will learn about during the DevConnections conference. This 1/2 day post-conference session will compare and contrast Object Services and Entity Client; Entity SQL, LINQ to Entities and LINQ to SQL providing guidance as to which methods are appropriate in particular scenarios. We will also examine this functionality with respect to both creating new solutions and plugging the Entity Framework into existing applications.

The Data Access track is part of both VSConnections & ASPConnections.

Choosing LINQ to Entities vs Entity SQL vs. EntityClient

The title is a bit of a misnomer and not comparing apples to apples. To do it right would have been longer. The real comparison is

“Choosing LINQ to Entities vs. Entity SQL+Object Services vs. Entity SQL+EntityClient”

When doing an intro session on entity Framework last night for GUVSM in Montreal, even though it’s something like the 7th time I’ve done this session (and every single presentation has been totally unique from any of the others I have done –  shaped by the questions asked), I think I finally figured out how I want to express this option of which query method you want to use. Even within those three options, there are more variations happening because they return different payloads and this can additionally be affected by whether or not you do projections (e.g. select firstname, lastname, age  instead of just select the whole object).

1) For me, Linq to Entities will always be the first query method I go for. I’m getting more and more comfy with LINQ since I’ve been using it with objects, SQL, DataSets and XML. Having all of that intellisense support is dreamy. Whether I use operators (From c in context.Customers Where c.CompanyName=”Acme Builders” Select c) or method operators (context.Customers.Where(Function(c) c.CompanyName=”Acme Builders”) it just makes my life easy! I’ve been using LINQ to Entities almost exclusively unless I have a reason to go to the next level.

LINQ to Entities still depends on an ObjectContext (and therefore uses Object Services) so you get all of the goodies that go along with that such as ChangeTracking, etc.

LINQ to Entities returns objects.

2) The next level is using EntitySQL with Object Services. That would be:

objectcontext.CreateQuery(Of Customer)(“Select VALUE c from Customer as c WHERE c.CompanyName=’Acme Builders'”)

The main reason I would want to use this is because Entity SQL is a very robust query syntax and I can express queries that LINQ (which is strongly typed) may not enable me to write. I want to be clear about my use of the word “dynamic” since I just mean that I can build the strings. You can also use parameters and as in most cases, should be careful about where and when you use dynamic queries (“select value c from customer where c.CompanName=” & myvariable).

As an aside, I’ve discovered that writing custom operators in Astoria, while possible with LINQ to Entities, is better in teh long run if you write them with EntitySQL. That is a conclusion made using the prototype so this may change down the road.

This method can return objects or dbDataRecords, depending on the query.

3) The method I see myself using most infrequently is EntitySQL with EntityClient. EntityClient is a db provider, similar to SQLClient or OLEDBClient. You create connections (EntityConnections) and commands (EntityCommands), set the command’s string (an Entity SQL query) and execute as you would other clients. The big difference between this and the other Client Providers is that you are connecting to your entity data model, not to a database.

There are two reasons to use EntityClient.

The first is if you do not want to return objects, but just streamed data, because EntityClient always returns a dbDataReader. This also means it’s a great candidate for helping you use an Entity Data Model in existing applications.

The other scenario (which is currently theoretical in my mind and has not be tested yet) where I can see myself wanting entityClient is if I have a data layer that needs to implement the Provider Factory class so that I can select my provider at runtime.

I’m ignoring another possible reason which is that EntityClient provides a familiar way of accessing data because it feels similar to using the other client providers. But because you lose your objects and all of the benefits of the objectContext, I don’t think the benefit of “smaller learning curve” is a worthy trade-off.

“The proof is in the pudding,” as they say and we saw the pudding last night at the GUVSM presentation because I have already gotten out of the swing of composing Entity SQL queries, while I’m getting to be a champ with LINQ to Entities.

Introducing ADO.NET Entity Framework Article in CoDe Mag Nov/Dec

While this is not online yet, I do have the latest issue of CoDe Magazine in my hands which has (among some other great articles!) an intro article I have written on Entity Framework.

I originally wrote the article using VS2008 Beta1 and Entity Framework beta1, then (as it always seems to happen) the Beta 2 bits of EF were released after the article was finished and with only a few days before the “going to print” deadline. But I was able to rerun all of my tests, through and make sure the content, the code and the screenshots were current, though I wasn’t able to add in too much info about the new designer. You’ll understand when you see how lengthy the article is.

I also wrote the MVP corner for this issue and finally got a chance to write about something that’s been on my mind for a while – and I think it’s kinda funny. I was a little surprised they let me write this one! 🙂

Unit testing LINQ to SQL and Entity Framework

Even though I’m still a Unit Testing luddite, I’ve been looking around to see how people are getting LINQ to SQL and Entity Framework to work in their Unit Testing scenarios even though neither technology is really built to test against well.

First, I found this excellent post by Ian Cooper that explained not just unit testing, but what makes code apprpriate for unit testing. This was really enlightening for this newbie  (that is, moi) and gave me a much better understanding of why the TDD guys have been so frustrated wtih Entity Framework – although it is absolutely evolving in a way that will satisify them (more likely V2, then V1 though).

Ian also was able to find a way to do Unit Testing with LINQ to SQL.

Then I headed back over to Danny Simmons’ blog for this recent post on some key tweaks to make to the EDM (and codegen’ed classes (and now my brain knows enough to say “uh oh… codegen…that’s a problem for Unit Testing!”) work with Unit Testing.

Then I started playing with VS2008 to get a feel for how the tools enable me to do unit testing when have zero experience. I had give in and read through documentation (I know , how lame and lazy am I?) after I spent about 1/2 hour searching for a screencast or webcast on the topic. But I got some of the basics and figured out debugging, but still have some definite quandries! (Such as why do I get a failure when the expected value is 10 and the actual value is 11, but I get an inconclusive (rather than a pass) when the expected value is 10 and the actual value is 10?) I have a lot to learn! 🙂

I found Chris Buckett’s post on shoving EF into vS2008 Pro unit testing which helped a lot, mostly because he already understands unit testing and therefore understands what challenges he needs to solve when working with entity framework objects. The biggest issue about unit testing data access modules is that you don’t necessarily want to hit the database each time. to this point, Chris is trying to create a mock provider to emulate the database calls made by Entity Framework. Another issue is that you need classes that are instantiated without parameters. So while Danny tells us the simple trick for getting regular classes to fit into unit testing (in the above linked post), Chris is struggling with how to create an ObjectQuery return without instantiating an ObjectContext because the latter requires parameters. (Surely, I’ve gotten some bit of my interpretation wrong in a way that is making you TDD pro’s cringe, but I’m trying! :-))

I am happy to sit by the sidelines while he comes up with the model. (Subscribed)

Get Ready for the MSDN Tour, Astoria and Entity Framework

The MSDN Events Tour for Q4 runs from Oct 16 – Dec 31 and hits 51 cities (including Burlington, VT!). One of the sessions is about Astoria* and it is called “A New Paradigm for Data Development with Web Based Data Services”.

Astoria sits on top of Entity Framework, and the session will also give a brief intro to Entity Framework, which thrills me to no end! I can only get to so many user groups to spread the love (which I’ll be doing next Monday, Oct 15th in Montreal by the way!).

If you are interested in preparing yourself better for Astoria by already having a clue about Entity Framework, you can look for my upcoming article in the Nov/Dec issue of CoDe Magazine called “Introducing Entity Framework”.

There are also a bunch of great resources you can keep an eye on:

My Data Access category on this blog

Roger Jennings blog

Mike Taulty’s blog

ADO.NET Team blog

And there are a number of team members writing about Entity Framework. I don’t even have a comprehensive list but I can highly recommend Danny Simmons blog.

For Astoria, check the Astoria team blog.

*my recent spate of astoria posts:

  • What the heck is Astoria?
  • QuickStart For Building An Astoria Data Service
  • More Fun With Astoria: Random Queries In The Browser
  • Astoria is sick (as in SLICK) when it comes to DML!
  • Trying to see what Astoria messages look like in the pipe
  • Custom Operations and Hiding EntitiesInAstoria