Sunday, July 08, 2007

I wanted to see some of the new Beta2 (in the June CTP bits) functionality of Entity Framework so I've been poking around. You can see a nice list of what to look for on Danny Simmons' blog.


One thing that was a huge source of frustration was the inability to support database constraints where a column was both a primary key and also a foreign key of another table. When using the EF Wizard to import database schemas, this would be part of a list of errors that were generated during the model creation and would result in a problem like this:

Notice that you can't get back to the ORDER that owns the Order_Detail.

With the new CTP, that problem goes away.

You can't traverse over Order_details because it is a  collection property, but you can get at properties like Count, etc...

Dim od = From o In NWEntities.Orders Where o.ShipCountry = "Spain" _
Select o.Customers.CompanyName, o.Order_Details.Count
    


Another thing, of course was the difficulty of working with existing views and stored procedures.

Here's a before and after of the wizard:

 

      

But the sproc and view support goes much deeper.

Unfortunately, I don't see the wizard carrying the views and stored procs all the way through. If you look at the SSDL, you will see that the views are described as any other table. The stored procs are <function> elements.

While I can't figure out how to surface the query function, there are also functions to let you use your own sprocs for insert, updates and deletes and tie them into EF's SaveChanges function. Shyam Pather wrote a post about this a while ago on the ADONET Team blog and now that stuff is in this version along with documentation examples.

Another SPROC goody is the ability to define your own stored procedures in your model without  needing it in the database. Check the DefiningQuery element that goes in the SSDL to achieve this.


Poking around in the CSDL, I see a few changes which tie back to the references.

A Key used to be an attribute of an Entity Type. Now it is an element.

Beta1:   <EntityType Name="Employees" Key="EmployeeID">

CTP:   <EntityType Name="Employees">
    <Key>
      <PropertyRef Name="EmployeeID" />
    </Key>


So that they could do this:

 <EntityType Name="Order_Details">
    <Key>
      <PropertyRef Name="OrderID" />
      <PropertyRef Name="ProductID" />
    </Key>

Which then enables us to do this:

  <Association Name="FK_Order_Details_Orders">
    <End Role="Orders" Type="Model.Orders" Multiplicity="1" />
    <End Role="Order_Details" Type="Model.Order_Details" Multiplicity="*" />
    <ReferentialConstraint>
      <Principal Role="Orders">
        <PropertyRef Name="OrderID" />
      </Principal>
      <Dependent Role="Order_Details">
        <PropertyRef Name="OrderID" />
      </Dependent>
    </ReferentialConstraint>
  </Association>
  <Association Name="FK_Order_Details_Products">
    <End Role="Products" Type="Model.Products" Multiplicity="1" />
    <End Role="Order_Details" Type="Model.Order_Details" Multiplicity="*" />
    <ReferentialConstraint>
      <Principal Role="Products">
        <PropertyRef Name="ProductID" />
      </Principal>
      <Dependent Role="Order_Details">
        <PropertyRef Name="ProductID" />
      </Dependent>
    </ReferentialConstraint>
  </Association>

Which is describing this from the database:


 Speaking of the database, there was mention of the fact that it's now easier to get at the underlying datastore. I haven't figured out how though, yet. I looked to see if you could now cast an EntityConnetion to a SqlConnection but that's not it. I'll keep an eye out for that. While I was looking though I noticed a bunch of new methods in the ObjectContext such as the pieces that go along with attaching and detaching such as "Addto" methods for each of the entities in the objectContext.


 The last thing I'll shove into this already long post is that Entity constructors are no longer auto-generated. This will make customization a lot easier (you can read about that in this post from Danny Simmons).

So where we had this in Beta 1:

  Partial Public Class Employees
        Inherits Global.System.Data.Objects.DataClasses.Entity
        '''<summary>
        '''Initialize a new Employees object.
        '''</summary>
        Public Sub New()
            MyBase.New
            'Call DoFinalConstruction if this is the most-derived type.
            If (CType(Me,Object).GetType Is GetType(Global.NorthwindModel.Employees)) Then
                Me.DoFinalConstruction
            End If
        End Sub
        '''<summary>
        '''Initialize a new Employees object.
        '''</summary>
        '''<param name="employeeID">Initial value of EmployeeID.</param>
        '''<param name="lastName">Initial value of LastName.</param>
        '''<param name="firstName">Initial value of FirstName.</param>
        Public Sub New(ByVal employeeID As Integer, ByVal lastName As String, ByVal firstName As String)
            MyBase.New
            Me.EmployeeID = employeeID

            Me.LastName = lastName

            Me.FirstName = firstName

            'Call DoFinalConstruction if this is the most-derived type.
            If (CType(Me,Object).GetType Is GetType(Global.NorthwindModel.Employees)) Then
                Me.DoFinalConstruction
            End If
        End Sub

Although the constructor is gone (along with the acrobatics that would require creating your own constructors) there is a new method for creating each entity:

     Public Shared Function CreateEmployees(ByVal employeeID As Integer, ByVal lastName As String, ByVal firstName As String) As Employees
            Dim employees As Employees = New Employees
            employees.EmployeeID = employeeID
            employees.LastName = lastName
            employees.FirstName = firstName
            Return employees
        End Function

Sunday, July 08, 2007 4:48:59 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Wednesday, July 04, 2007

By default, when querying entities, you need to explicitly use the Load method to get related data. This is often called "lazy loading" and ensure you only get what you ask for rather than having a query return ALL related data automatically. The new SPAN method forces an entity to include specifid children during a query so that you don't have to load after the fact. READ MORE

[A New DevLife Post]

 

Wednesday, July 04, 2007 11:18:49 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Tuesday, July 03, 2007

Danny Simmons has a great list of changes to Entity Framework that have finally arrived in the latest CTP. These improvements are not insignificant and the list is filled with functionality that many of us have been really looking forward to. I' feel a little harnessed having to use VWD Express right now and haven't touched all of these things. But I was happy to see Views & Sprocs listed in the wizard and NOT to have the damn code gen message telling me that associations can't be created for a key that is both a foreign key and a primary key. That means Orders will be able to find their details again!

The default constructors are gone in the code gen class but it's hard to see since the code generated class is not exposed in the web site. I was able to find the compiler code version deep down inside of

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\website2\5618daca\5d6fd1a4\Sources_App_Code\model.csdl.[guid-type number].cs.

That's just the toplevel stuff. I'm looking forward to digging down a little deeper to play with SPAN and well, just about everything on Danny's list.

Tuesday, July 03, 2007 9:46:53 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 

Note that the installation instructions for the June CTP of VWD (which the June CTP of Entity Framework installs on top of) have changed. See the ADO.NET Team blog for the updated version of the post.

Tuesday, July 03, 2007 9:17:06 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Monday, July 02, 2007

The ADONET Team today announced that the June CTP of Entity Framework is available. It is currently only available packaged with the June CTP of Visual Web Developer Express. Being a CTP release, they have just done enough to get something in our hands so we can see what they are working on.

A lot of what is in here is what I saw Brian Dawson using at DevConnections in March.

The ADONET team blog post lists the changes to look for and makes some important notes about the installation.

I'm off to download!

Monday, July 02, 2007 7:26:38 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Monday, June 25, 2007

While at TechEd, David Sceppa wrote about the status of various database vendors as they create proviers for LINQ and Entity Framework. read more

[A new DevLife post]

Monday, June 25, 2007 2:54:06 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Tuesday, May 29, 2007

The ADO.NET team is conducting a focus group about Linq to Entities during TEchEd. Unfortunately, they posted this today and the deadline to sign up is today.

Here's the info to sign up.

I won't be at TEchEd this year and neither will Roger Jennings, but Roger has already created a great list of points he would bring up if he was there. I basically second all of his suggestions. Many of them point to clarity on Microsoft's messaging around Entity Framework (though I personally feel comfortable with this at this point) and then technical details such as being able to deal with perfectly normal relationships between data...you can read what I mean by this if you check out this forum thread.

Tuesday, May 29, 2007 8:05:39 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Monday, May 14, 2007

I guess we can't call it ADO.NET Orcas any more.... I guess the right name will just be ADO.NET 3.5.

Monday, May 14, 2007 8:46:45 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [2]  | 

In my short span betwee MIX and DevTeach (leaving tonight), I've been heads down playing with Silverlight's Inking capabilities and preparing for my DevTeach sessions and avoiding dealing with the delay of EF.

In the meantime, Roger Jennings continues to organize all of the info about ADO.NET Entity Framework into comprehensive posts such as this one.

Mike Taulty's library of LINQ to SQL videos has grown by orders of magnitude. Now he's posting LINQ to XML. When I see how many 15-20 minute videos it is taking Mike to demo and explain LINQ to SQL in a way that is satisfactory, it keeps making me laugh at the absurdity of covering whatever I can manage to squeeze into conference sessions that range from 60 - 90 minutes. Mike definitely has the right way to acheive this!!

 

Monday, May 14, 2007 8:29:47 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [2]  | 
 Thursday, May 03, 2007

These two incubator projects build on top of the Entity Framework. It's a very early look at what the data access team is working on. READ MORE HERE

[A New DevLife Post]

Thursday, May 03, 2007 1:39:16 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Tuesday, May 01, 2007

In Pablo Castro's session today, I noticed a link on the resource page to his own blog. I have never known that Pablo (tech lead on the ADO.NET team) had a blog and couldn't believe that I could have missed such a thing. Luckily there is wireless available at the conference so I immediately browsed to the blog and lo and behold, he had made his first post just today! It is on the Astoria Web Data Services.

http://blogs.msdn.com/pablo/

Tuesday, May 01, 2007 12:00:05 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Monday, April 30, 2007

I was wondering what "data services in the cloud" ... Pablo Castro's Mix Session, was going to be about.

Project Astoria exposes data that is exposed through the Entity Framework. So you build your EDM and then the service sits on top of htat.

It is two way... you can use HTTP PUT, POST and DELETE.

Here is a post on the ADO.NET team blog about the project Astoria, that is the web data services.

I'm in Pablo's talk right now, but you can check out the project here  and the blog post here.

The second one is called Jasper which is for purely data driven apps. I'm looking forward to Sam Druker's talk on this on Wednesday. Read the blog post here.

Monday, April 30, 2007 5:37:21 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Sunday, April 29, 2007

Mike Pizzo writes a post about Microsoft's data access strategy that covers a few important things:

1) Announces that EF will not make it into the Orcas release but will ship "A few months after the shipment of Orcas, and within the first half of 2008". This plan will allow them to give us more than what they would be able to give us in the initial Orcas release.
2) Addresses the LINQ to SQL vs. Entity Framework question, which has been asked quite a lot.

READ MORE HERE

[A New DevLife Post]
 

Sunday, April 29, 2007 9:22:23 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [1]  | 
 Thursday, April 26, 2007

Mike Taulty has been doing short screen casts about LINQ to SQL. I love his approach as I know from experience how difficult it is to try to give a decent presentation of LINQ to SQL in a single 90 minute session when you have to start from scratch.

There are 9 so far and more coming. Here is a link to the latest (that includes links to the first 8 as well). Stay tuned for more.

Thursday, April 26, 2007 8:28:43 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 

From the ADO.NET Team blog:

Late last week, after bits had been finalized, we found a bug in the ADO.NET Entity Data Model Wizard that shipped with Visual Studio “Orcas” beta 1. The problem has now been corrected.

 

Please download and install the patch available at: http://www.microsoft.com/downloads/details.aspx?FamilyID=f69e9eb8-0ebd-4fba-a4cc-2050297ba75b&displaylang=en to fix the problem.

 

Thursday, April 26, 2007 7:49:50 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Sunday, April 22, 2007

Although I haven't gotten my Beta1 bits quite yet , I'm keeping an eye on the ADO.NET Orcas forums and saw that apparently something broke in the Wizard that creates an the schema files from a db. Lance Olson from the ADO.NET team posted that they are aware of the boo-boo and there will be a fix/workaround posted in the next day or two.

Sunday, April 22, 2007 8:19:35 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [2]  | 
 Saturday, April 21, 2007

Check out this post from Mike Dodaro, which begins with:

What else do you need to know about the Entity Framework?  We've documented basic syntax and provided a few samples.  How can we improve the documentation?  Send us scenarios you want to implement.

Saturday, April 21, 2007 8:32:56 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Wednesday, April 18, 2007

huh?

[A New DevLife Post]

Wednesday, April 18, 2007 5:21:04 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Monday, April 16, 2007

I found some interesting ADO.NET labs and sessions on the MIX site today!

SESSIONS

Accessing Data Services in the Cloud
Speaker(s): Pablo Castro - Microsoft
Audience(s): Designer, Developer
Come learn about new Microsoft technologies that enable you to make your data available over the Web through a simple REST interface and using open formats such as plan XML, JSON or even RDF. We also discuss the underlying entity framework that makes it easy to model, publish, and program against your data over the Web.

Rapidly Building Data Driven Web Pages with Dynamic ADO.NET
Speaker(s): Samuel Druker - Microsoft, Shyam Pather - Microsoft
Audience(s): Developer
Come learn about how new technologies from Microsoft bring together the concepts of dynamic languages and ADO.NET and allow you to quickly develop data driven Web pages using ASP.NET dynamic data controls, scalable to even the most complex databases.

*note that Andrew Conrad wants to make sure you notice the word DYNAMIC in that session!

Deep Dive on Data Driven Experiences
Speaker(s): Aaron Dunnington - Microsoft, Tim Scudder - Microsoft
Audience(s): Developer
Come learn how technologies like Silverlight, Language INtegrated Query (LINQ), and SQL Server 2005 can help developers build impactful, dynamic applications that reach the broadest possible audience.

LABS

REST Services for Data Access over the Web
Audience(s): Developer
In this lab, build a data service accessible through REST that supports exchanging data in XML and JSON formats, with full query and update capabilities; and build an AJAX-based client and a managed code client.

Rapidly Building Data Driven Web Pages with Dynamic ADO.NET
Audience(s): Developer
In this lab, learn about Project Friday, an incubation effort in the ADO.NET team to enable quick, clean, and iterative development with instant results. Project Friday provides this functionality by leveraging the ADO.NET Entity Framework and the power of dynamic languages.

Monday, April 16, 2007 10:08:53 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Sunday, April 08, 2007

Yay yay yay. I am not sure when this happened, but I just discovered that Pablo Castro will be doing the keynote at DevTeach (Montreal, May 14-18) and not surprisingly, he'll be talking about the Entity Framework. More here.

Sunday, April 08, 2007 9:56:12 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Saturday, April 07, 2007

There are a lot of us who have been looking forward to this show being posted: Daniel Simmons on ADO.NET Entity Framework. Now I have to find some time this weekend to listen to it. Roger Jennings has a fantastic analysis of the show here. While at DevConnections, Richard and Carl were talking about how much fun this show was to do. They didn't know anything about Entity Framerwork when they started and were definitely fascinated with it. I'm glad that more people are going to get exposed to EF!

Here is a link to Danny's blog.

Saturday, April 07, 2007 7:54:20 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Thursday, April 05, 2007

It's not often that one sees their name right next to Anders' (especially considering that I'm a VB programmer :-)), but check out this LINQ article in the  current issue of Redmond Developer News. While the focus is Anders and this great technology he and others (and always with a nod to Alan Griver) are bringing to Visual Studio .NET, I was asked to give some developer perspective.

I'd also like to say that I wasn't literally jumping up and down at PDC. :-)

I know that I have had the same reaction when watching Scott Guthrie present on LINQ to SQL. I think I'm jumping up and down with joy, but truly my butt remained glued to the chair.

It was fun talking to Michael Schwarz about this, but I think I may have overwhelmed him with my geek technical perspective of LINQ from which he was trying to extract key points for dev managers. He seems to have done a great job.

Michael talked to another developer, VB guru Bill McCarthy who gave him a great analogy quoted at the end of the article.

Thursday, April 05, 2007 10:33:50 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [3]  | 
 Wednesday, April 04, 2007

A recent LINQ forum question asked about the differences between Linq to SQL and the Entity Framework.

This is the response that I wrote and thought I would surface it in my blog:

 Besides that Linq to SQL is only for SQL () one of the big differences is that the EDM is more flexible and more loosely coupled because of the 3-tiered model (conceptual layer, source schema and the mapping layer in between).  For example, you could have one conceptual layer and then multiple mapping layers that point to mulitple databases. In LINQ to SQL, your dbml properties are tightly bound directly to one particular field in a table.

While these are not in the March 2007 CTP, EDM is getting the ability to build views of the conceptual layer as well as to write stored procedures in the mapping layer. These are really cool features. I don't believe you can do this with Linq to SQL, but a) I could be mistaken and b) that may be something that is forthcoming.

In addition to Linq to Entities, Entity SQL can be used to query entities. This can be either through the object services API or the Entity CLient (the one which gives you connections/commands and results in a dbDataReader). Entity SQL, while not as elegant as using the strongly typed LINQ, has the advantage of enabling dynamic queries, since you use a string to build a query, much like TSQL.

Both Linq to SQL and EDM allow inheritance and extending the code generated class with addtional partial classes. EF allows many to many relationships. I believe that LINQ to SQL will NOT be getting this by RTM.

These are just a few points and hardly exhaustive. But to me they are the low hanging fruit.

Wednesday, April 04, 2007 9:47:39 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Friday, March 30, 2007

Fabio Claudio Ferracchiati has a book on LINQ that he wrote against very early bits. When the March 2007 CTP came out, he blogged a list of things that he discovered had changed in LINQ syntax that required updates to his book. The list is handy if you have code even from the January CTP.

Friday, March 30, 2007 9:13:34 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [4]  | 
 Wednesday, March 28, 2007

I am at DevConnections where I was VERY excited to see Brian Dawson (ADO.NET team) do not one but TWO Entity Framework talks on Monday.

Brian has a newer build than what we are working with in the March CTP and I saw some stuff that made me wanna whine "gimme gimme".

  • SPAN - calling span on an entity sql query will force the ObjectContext to load up an object's entire hieriarchy without having to call Load after the fact to get related data. This seems to be available in Object Services but not through Linq to Entities. Hopefully an Extension Method will be created for Linq to Entities to give us access.
  • The EDM Wizard will display Views and Stored Procedures when building an EDM from a database. Then these will be part of the schemas.
  • Referential Contraints will work the way you would expect. For example if your db has a referential constraint to delete child records when a parent is deleted, EDM will pick those up. I don't know the details here but am assuming we will have some granular control over this.
  • ToList may not be necessary in the future and serialization will be implicit.
  • Beta 2 will have something (new to me) called IPOCO... Interface for Plain Old CLR Objects
  • QueryViews - ooh baby ooh baby. Create your own views in the mapping layer.
  • Associations between sub types.
  • There will be a way to convert existing strongly typed datasets to entity schemas. Unfortunately either Erick (who I got this from) misunderstood the question or I misunderstood the question or I misunderstood the answer. Darn.

At the same time as DevConnections, VSLive was happening in San Francisco. (Quite unfortunate scheduling...) Britt Johnston did a keynote and showed [a video of] the latest prototype of the EDM Modeler and also let us know that it won't be ready for Orcas but they plan to release it shortly (?) (well the quote from the ADONET blog post is literally "sometime") after Orcas. This is really frustrating, but it is just the reality and as developers we know the difficulties of designing tools... so it is what it is and until we have it, I will learn a LOT with the XML and personally hold off on doing any seriously complex modeling.

See the ADONET Team blog and Data Blog for more on Britt's keynote and links to the screencast on where the modeler is at today.

I did my ADO.NET Orcas overview talk yesterday to a full room (not a huge room, but still all the seats were filled which was great given that Carl Franklin and Richard Campbell were doing a live DotNet Rocks show with Scott Guthrie at the same time!). I love talking about this stuff even if I never seem to have enough time for all the cool stuff I wish I could show.

Wednesday, March 28, 2007 8:53:45 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [6]  | 
 Sunday, March 18, 2007

Last week, I inaugurated my ADO.NET Orcas Overview at the TEchValley.NET User Group in Albany NY (with thanks to INETA!!). It was a serendipitous night for me to present there as they had just moved to new digs for their meeting, a very convenient, spacious and high tech location, so they packed the room!

The purpose of this presentation is to introduce developers to the Entity Framework and to LINQ for ADO.NET (that's the umbrella term for LINQ to SQL, LINQ to DataSets and LINQ to Entities) and while it sounds like a short list, it's a LOT to cover in one session. Especially if you don't want to just do some marketing. Developer's want to see code, but there is a lot of high level explaining to do up front, which takes time. Yet, I can't help wanting to desconstruct the Entity Data Model schema files, try to show different ways of designing a conceptual layer, and then the many ways of getting data out of the entity framework as well as using LINQ to SQL (a huge topic all on it's own) and LINQ to DataSets (another good sized topic, if you like DataSets, which I do!). Minimally, a day would be good to start with.

Before I opened up the schema files, I asked "so, who here is comfortable working with XML, anyway?". I was surprised that 1/3 of the hands went up. This is a smart group of developers who challenged me with a lot of awesome questions! (Though there was a big sigh of relief when I mentioned LINQ to XML and LINQ to XSD for those of use who live in fear of XPath!)

I laughed at John Papa's recent blog post where he bemoans the difficulty of cramming the same list of info into an article he is writing for MSDN Magazine. John and I have been providing lots of moral support to each other as we attempt to wade through Entity Framework and the LINQ flavors that are involved with data access. I was happy to finally meet John in person at the meeting, as well. (A local yokel!)

The most laughable part of my session was when, after constantly checking my watch to gauge how much time I had left (and being surprised, at each check, how well I was doing with the time), I realized that I hadn't changed the time on my watch for the early daylight savings time. I didn't have 1.5 hours to go, but only 1/2 hour! While I had planned to do a 2 hour session (user groups are a little more amenable to this than conferences where you are on a tight schedule), I think that, not counting the short break we took, I managed to wrap up in 2 hours and 15 minutes - and nearly everyone stayed! But what's new? (Hey, you've got me there, take advantage of it! ;-))

The next day, I had a three hour drive home, immediately followed by a GeekSpeak webcast on the same topic, but for only one hour. My favorite part of this format was that whenever I was starting to go on and on about one particular piece of the Entity Framework (can't be helped as I find it fascinating - sick, huh?), Susan would steer me to the next stage of the discussion. Boy, would I love to have Susan with me while I'm presenting at a conference. "Okay Julie, I think 5 minutes looking at XML is more than enough... let's go look at something a little sexier, like the LINQ to SQL designer, huh?"

So next up is DevConnections, where I will be doing this session in 75 minutes (less, if I want to be able to answer questions), then on to Code Camp in Waltham, then the South Sound User Group in Olympia (after talking about LINQ to SQL In Bellingham, WA - both INETA gigs) and DevTeach in Montreal. I'm excited about all of these opportunities to introduce developers to these very cool technologies!

Sunday, March 18, 2007 10:11:25 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Saturday, March 17, 2007

From the forums (this thread):

A future version of SqlMetal.exe will generate DataContract and DataMember attributes on your entities for you.  Putting them on the DataContext won't work because the DataContext is not serializable.  (Matt Warren, Microsoft)

Saturday, March 17, 2007 10:17:54 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Friday, March 16, 2007

There are some great questions bubbling up in the forums. THe ADO.NET team is busy in these discussions as well as writing some good blog posts on Entity Framework. Here's the current run down...

[A DevLife post]

Friday, March 16, 2007 4:16:20 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Saturday, March 10, 2007

GeekSpeak is a lot more free-form than a typical webcast and I'm not sure what to expect. I'll have the new CTP of ORCAS open and I guess we'll poke around Entity Framework and the three LINQ to ADO.NET techs (LINQ to SQL, LINQ to Entities nad LINQ to DataSet). And the most fun part is that I'll be doing this with hosts Glen Gordon (who I did a webcast with on ADO.NET 2.0 topic a few years ago) and Susan Wisowaty (who lives right here in Burlington!), from the MSDN Events team.

More info and registration here

Saturday, March 10, 2007 1:44:24 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Thursday, March 08, 2007

Erick Thompson from Microsoft followed up on a thread about where ToDataTable went in the march CTP. http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1300671&SiteID=1

Thursday, March 08, 2007 11:16:50 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [2]  | 
 Tuesday, March 06, 2007

I've noticed that the posts on the ADO.NET and LINQ forums for Orcas have completely subsided after a flurry over the weekend. I guess everyone had to get back to work!

Tuesday, March 06, 2007 7:45:00 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 

There are SO many ways to "skin the data access cat" in Orcas that I'm getting a little cross-eyed. (Though this could be from looking at all of the XML in the Entity Data Models.)

I thought I would try to sort it out a little here since I have done this for some of the presentations I am putting together.

ADO.NET in Visual Studio Orcas

The "new" ADO.NET is not new, but added to. Evolution and backwards compatibility are key to the ADO.NET team. So in Orcas you will have what you know as ADO.NET 2.0 basically in tact. Then added onto that are two things: Entity Framework and integration with LINQ.

LINQ Integration in ADO.NET (in VS Orcas).

Painting a broad brush stroke to define LINQ is that it gives you the ability to query in-memory objects (that are iEnumerable).

 While there is the basic LINQ to Objects syntax, there are four derivatives of this.

LINQ to XML allows you to use LINQ to query XML.

There are three others that all fall under the umbrella of LINQ to ADO.NET.

The first of these is LINQ to DataSet. DataSets are in-memory objects, right? So we can query them, too. What we are really querying is an Enumerable collection of DataRows. Because of the special nature of DataSets, this "flavor" of LINQ needs to be specialized.

Next is LINQ to SQL. Of course, this taints my brushstroke because SQL is not an in-memory object. :-) However, as long as we have this fabulous new language enhancement, and we are all over querying databases, this version of LINQ was created to work directly with SQL, not only to query, but to update the data as well.

The last of the LINQs is LINQ to Entities. This lets us use LINQ to query the objects that are created by the Entity Framework. So let me jump to that and then come back to this one.

Entity Framework

Entity Framework is a whole new set of APIs added into the System.Data namespace.

The key to the framework is a set of three schema files.

The first file describes the conceptual layer of your business entities using a schema file. This is not replacing your objects. All we are describing is structure and basic metadata. Two of the (many) big advantages of this are that 1) in the end, we can write our data access code against this schema (which creates classes for us) rather than having to code up connections to the db, create complex joins to pull together info from various related tables and write lots of update logic and 2) we can describe these conceptual entities based on what we want them to look like, rather than how they are best organized in a database.

The second files describes the schema of the database, including pk/fk relationships.

The third file is a map between the first two. So that when you code against the entities, the framework can translate your requests (or updates) into what the database is expecting.

So those are just three files (which can be created directly from your db using a wizard or a command line tool and then edited manually).

Interacting with the schema files

There are two APIs that know how to make these schemas do their magic, Object Services and Entity Client.

Object Services

Object Services know how to work with the entities as objects. You can query against the entities and get objects as your results. These objects are managed in memory by Object Services and you can update the database easily with changes made to the objects. So I said the magic word, query.

There are two ways to query with the object services. 1) Directly using (yet ANOTHER query syntax...) Entity SQL, which is similar to using SQL and is built using strings. Here you would use the ObjectServices API to create a query object and then pass in the Entity SQL string 2) Indirectly using LINQ to Entities. If you use LINQ to Entities to query the entity classes, in the background LINQ to Entities will use Object Services to interact with the objects. Either way, ObjectServices will maintain in-memory knowledge of the objects for updates.

There are  providers being built to interact with other databases. Regardless of the database, once the schemas and mapping are built, everytihng you do on the client side will be the same.

A caveat is that if you use Object Services plus Entity SQL to query and in your query you use projections (request specific columns/properties instead of entire objects) you will not get an updatable object. Instead you will get an IEnumerable collection of DbDataRecords. LINQ to Entities will return objects even with projections, because that's what LINQ knows how to do.

Entity Client

The last thing I wanted to talk about is Entity Client, the other way to access entities. EntityClient is a provider, similar to SQLClient and the others. It let's you build your data access code to query the entities in a familiar way, with connections (though the connection points to your entity objects) and commands. With EntityClient, you build queries using Entity SQL syntax. EntityClient queries return a dbDataReader. You cannot do updates directly through EntityClient. An interesting thing about this provider is that if you are building an app that leverages the Provider Independent API, you can have code that easily flips back and forth from access data in SQL Server, Oracle, Access, or other data engines. So (though I haven't tested this, I'm making an educated guess here) you can add EntityClient into this flexible model.

Summary

So now you can see why I'm a little cross-eyed. We are working with 6 new query languages (though they are all related),5 new ways of accessing data, trying to keep track of which syntax goes with which access method and which access method returns what type of data. And it is dizzying for sure. But after some investment in this, I have definitely gotten it sorted out. And you can too!

 

Tuesday, March 06, 2007 12:05:33 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [2]  | 
 Monday, March 05, 2007

I wrote up a list of some of the invaluable resources I have been relying on while diving deeply into the new March CTP of Orcas.

[A DevLife post]

Monday, March 05, 2007 9:08:56 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 

In a previous interation, I managed to track down some sample code that built a LINQ call to a stored procedure, the class which it returns and executed it in LINQ to SQL.

The code has changed dramatically in the March CTP. Luckily, Mike Taulty beat me to it and I leveraged the C# code in his post to revise mine.

One of the things I was so silly to do in my previous test was to hand code the return class rather than just create it in the designer and return that.

But all of this is not totally necessary since you can now drag and drop stored procs onto the LINQ to SQL Visual Modeler and make calls to it. Interestingly the return type is just created on the fly at run time so it's not even an issue - yay to anonymous types.

However, it's still nice to know how to build this stuff becasue drag n drop doesn't solve every coding problem. So check Mike's post for the C# version.

Here is a working version in VB.

"CustOrderHist" is the name of the stored procedure in my database. 

What this is doing is

1) using the attribute to hook it up to the sproc
2) taking in a parameter of customerID and associating it with the parameter @CustomerID in the stored proceudre
3) Returning and IEnumerable of type CustOrderHistoryResult (the class I created in the designer that matches the structure of what the sproc returns).

On the client side, I can now take the result and do whatever I want with it, such as bind it to a gridview on a web page.

<StoredProcedure(Name:="CustOrderHist")> _
Public Function GetCustOrderHist(<Parameter(Name:="CustomerID")> ByVal customerID As String) As IEnumerable(Of CustOrderHistoryResult)

  Dim result As IQueryResults(Of CustOrderHistoryResult) = _
 
ExecuteMethodCall(Of CustOrderHistoryResult)(Me,
  MethodInfo.GetCurrentMethod, customerID)
    
  Return result

  End Function

Monday, March 05, 2007 4:52:17 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Friday, March 02, 2007

VB9 has come a long way in the new March CTP of Orcas! Paul Vick has a quick list of what is now in there. And there are a lot of good details in the msdn documentaiton that comes along with the CTP.

A few things I noticed quickly when bringing my LINQ for SQL demos over to the new bits.

  • First, and happily, the named parameter syntax of := is no longer necessary. You can just type =, like a normal person.
  • You need to be explicit about using the reference to the entity when refering to properties. In other words where I could say
     From s In db.Suppliers_
                Where CompanyName = "Exotic Liquids" ...
    I now need to put  "s." in front of the CompanyName property
  • The anonymous types have been fleshed out more and you need to use the With keyword when creating one.
  • Also in the anonymous types, when you are definining a new named parameter, you need the "." in front of that parameter, so it is obviously a property of the anonymous type.
  • Maybe this isn't the ultimate way to do it, but it seems that if you want to further leverage one of the properties of that anonymous type, eg to order on, then you need to name the anonymous type and reference it in the order by clause. Again, maybe this isn't THE way, but it's the way I got my code working again.

Here's a before (as in earlier CTP) and an after (March CTP) example of a simple query that does all of these things.

OLD
From s In db.Suppliers _
            Select New {Company := CompanyName, Country, Products}

NEW
From s In db.Suppliers _
            Select New With {.Company = s.CompanyName, s.Country, s.Products}

Here's what it looks like with a nested query
  From s In db.Suppliers _
            Select New With {.Company = s.CompanyName, s.Country, _
            .Products = (From p In s.Products _
                Select New With {p.ProductName})}

OLD with Order By
From s In db.Suppliers _
            Select New {s.CompanyName, s.Country, s.Products} _
            Order By CompanyName

NEW with Order By
  Dim mylist = From s In db.Suppliers _
            Select s2 = New With {s.CompanyName, s.Country, s.Products} _
            Order By s2.CompanyName

I've seen samples where "s" has been used for both the reference to the items in the db.suppliers collection AND to the name of the new anonymous type. That scares me, so I used a new variable (s2).

There is also a whole new set of query samples in the MSDN documentation.

Friday, March 02, 2007 2:38:37 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [5]  | 
 Thursday, March 01, 2007

The ADO NET Team has been cranking out fab content on their blog. Brian Dawson just wrote a post all about Object Services.

In trying to sort out all of the options that we now have with Entity Framework and LINQ, I'm always happy to see a list like this. But go read the whole post so nothing is out of context

What can you do with Object Services?

Here’s a bullet list of some of the normal operations which object services can provide:

·         Query using LINQ or Entity SQL

·         CRUD

·         State Management – change tracking with events

·         Lazy loading

·         Inheritance

·         Navigating relationships

More features of Object Services allow for data conflicts resolution. For example, Object Services supports:

·         Optimistic concurrency

·         Identity resolution -  keeping on copy of the object even from several different queries

·         Merging

·         Refreshing data with overwrite options (ie: server wins or client wins)

Thursday, March 01, 2007 10:01:53 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 

I saw mention of this new version of the command line tool in this forum post so I went looking in the MarchCTP. I modified some of the desciriptions a little to fit them onto a powerpoint slide, so this is a tad different than the real tihng

C:\WINDOWS\Microsoft.NET\Framework\v3.5.20209>edmgen /help


Microsoft (R) EdmGen version 2.0.0.0
Copyright (C) Microsoft Corporation 2006. All rights reserved.

                                           EdmGen Options
/mode:ValidateArtifacts                 Validate the ssdl, msl, and csdl files
/mode:FullGeneration                    Generate ssdl, msl, csdl, and objects from the database
/mode:FromSsdlGeneration                Generate msl, csdl, and objects from an ssdl file
/mode:EntityClassGeneration             Generate objects from a csdl file
/mode:ViewGeneration                    Generate mapping views from ssdl, msl, and csdl files
/project:<string>                       The base name to be used for all the artifact files (short form: /p)

/connectionstring:<connection string>   The connection string to the database that you would like to connect to (short form: /c)
/incsdl:<file>                          The file to read the conceptual model from
/inmsl:<file>                           The file to read the mapping from
/inssdl:<file>                          The file to read the storage model from
/outcsdl:<file>                         The file to write the generated conceptual model to
/outmsl:<file>                          The file to write the generated mapping to
/outssdl:<file>                         The file to write the generated storage model to
/outobjectlayer:<file>                  The file to write the generated object layer to
/outviews:<file>                        The file to write the pre generated view objects to
/language:Vb                            Generate code using the VB language
/language:CSharp                        Generate code using the C# language
/namespace:<string>                     The namespace name to use for the conceptual modely types
/entitycontainer:<string>               The name to use for the EntityContainer in the conceptual model
/help                                   Display the usage message (short form: /?)
/nologo            &nb