Monday, April 07, 2008

Spring has arrived in Vermont, but I'm leaving.

This afternoon I start my overnight journey to Stockholm where I will be participating in the Developer Summit 08 and have been working with Patrik Lowendahl and Mats Rydin who are coordinating. Patrik's company, Cornerstone is instrumental in this conference and everyone there has been wonderful in helping get me prepared.

I'm really looking forward to it. Stockholm is an incredibily beautiful city with lots of history and I've never been there before. Plus there's a great line up of speakers some who are friends that I always look forward to hanging out with and others who I am looking forward to finally meeting! And David Chappell, who is coming by way of Eilat Israel (a 2 day trip) from TechEd, is giving the keynote!

When I have asked anyone if they want me to bring anything back for them, they all have said "oh, yes, a beautiful Swede!" Well at least my single friends have made that request.

Swedish is not among the languages I ahve ever studied so I was happy to find some really useful lessons on Survival Phrases.com. I downloaded a bunch to my iPod to listen to again if I need them. They don't just say how to say a phrase but when it's appropriate as well as providing other background.

I still needed to see what these words look like so a simple list like Basic Swedish Phrases provides good backup. This won't enable me to give my presentatino in Swedish, but at least I can be polite when I have to find the toaletten.

I'll be doing an Advanced EF Session, a talk on Silverlight Annotation and on Friday a full day workshop on Entity Framework including some Hands on Labs. It should be a blast.

And even with my dreadful lschedule right now, I'd be a fool not to at least poke around Stockholm so I am flying home on Sunday (6am flight -uggh) and will have Saturday off to be a tourist.

Monday, April 07, 2008 10:02:58 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [1]  | 
 Saturday, April 05, 2008

In my previous post, I managed to update a simple model from an existing database. But then I started trying to do things like build my project and ran into so many problem trying to get my simple model to interact with the AdventureWorks database that I finally gave up.

I actually wrote my thoughts on this in a question on the MSDN forum for Entity Framework, with the point of the question being "is there a real example of this? Or is it just a concept that looks good on paper?"

I care a lot about this becuase I have been sharing this concept (which does make sense to me) that the EDMs loose coupling to the database means that you could map the CSDL to different databases.

But the AdventureWorks database just had too many constraints - such as non-nullable fields that I didn't have in my model and I finally gave up because it was forcing me to modify the CSDL and I would also have to add in some business logic to deal with some of these non-nullable fields. And even if I did that, who knows what other problems would pop up?

Update after I gave myself a little time while eating lunch to think about this some more, I crossed out "finally gave up" becasue it's basically not in my nature. I decided to go about this in a different direction with just ONE entity and succeeded by removing the unused non-nullable fields from the SSDL and mapped the entity to Insert/Update/Delete sprocs. All I have to say to myself at this point is "well, duh!" The insert stored proc provides the missing non-nullable fields and the update stored proc updates the modifieddate for me. SO problem solved in a not very realistic example, but I plan to build it up thought not today - I've already invested too much time. There's a lot of flexilibity in the model, but we all still have a lot of learning to do for our various use cases.

You can read my more complete thoughts on this in the forum post and if you want to follow the conversation you can sign up to get alerts on this thread from the MSDN forums.

Oh, and if you've never signed up for alerts before, you might want to read this blog post I wrote last summer: A few MSDN Forums tips (which I learned the hard way - as usual).

Saturday, April 05, 2008 12:47:18 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 

When you use the UpdateModel feature of the Entity Framework design tools, the process relies on matching up existing entity names to table names, more specifically name of objects in the CSDL with names of objects in the database.

IF you have selected objects to add and nothing with that name already exists, it will add a new entity in the model, otherwise, it will use the existing entity.

There are changes coming to how this works detailed in this blog post by Noam Ben-Ami.

But I got bit by something that I overlooked which took hours to pinpoint the cause of the problem, so I wanted to share it.

I had created a model from scratch that was a simple, generic commerce app (see image below). I created entities for Customer, Order, LineItem, Address and Product with some properties, entity keys and associations.

Then I linked it up to  a database using UpdateModel to create the SSDL for me but nothing happened.

It took a lot of experimenting before I realized that the problem was that I was trying to add in a CustomerAddress table but I had an association named CustomerAddress. If that had been an entity, it wouldn't have posed a problem. But the wizard did not know how to handle the fact that it was an association and just completely gave up the ghost.

The only problem I see here is that some indication of the conflict would have helped me figure out what was wrong a little sooner, though I don't expect the wizard to overcome the conflict on its own. I did make a note of this in the forums. However, I am putting the info here for posterity in case it's too late to change the wizard for RTM and somebody else gets stuck on the same problem.

Saturday, April 05, 2008 9:28:29 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Friday, April 04, 2008

Here's the story of where the new movie The Forbidden Kingdom comes from  - bedtime stories told by a man who lives nearby in Morrisville, VT to his son.

I just watched the trailer online and it looks awesome. I love the fanastical Jet Li kung fu style movies including of course, the Kill Bill series. Oddly, I can't bare to watch violent films but love this genre.

Friday, April 04, 2008 4:26:31 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 

Over the next few months I'll be presenting at 4 conferences in Stockholm, Orlando, Toronto then again Orlando. I'll be doing talks on Entity Framework, Astoria, Silverlight and Data Access in general. Details and links are here...

[A New DevLife Post]

 

Friday, April 04, 2008 3:05:21 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 

I've written a set of Entity Framework (and one which is more general for LINQ to Entities and LINQ to SQL) tutorials that are on DataDeveloper.NET Tutorials page.

Most of these are beginner basics. The "101 Tutorials" are designed to make sure new programmers don't get completely lost. So if you need the extra handholding, it's there, if not just skim over it to get to the juicy bits.

The Tutorials so far are:

101 Tutorial:Creating an ADO.NET Entity Framework Entity Data Model

101 Tutorial: Use an Entity Framework Entity as a WinForms Data Source

Many to Many Relationships in the Entity Data Model

Using Stored Procedures for Insert, Update & Delete in an Entity Data Model

Naming conventions in an Entity Data Model: Cleaning up the wizard-generated EDM

Adding items to a LINQ Query of anonymous types - after the fact

101 Tutorial: ASP.NET DataBinding with the Entity Framework

101 Tutorials: WPF Databinding with Entity Framework

Friday, April 04, 2008 2:41:24 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Thursday, April 03, 2008

Debug breakpoints stopped working in my Silverlight 2.0 project.

There's one very good reason why debugging won't work which Karsten blogs about in his post "What To Do When Breakpoints Disappear and Debugging Dies In Silverlight 2".

But that wasn't my problem. I had SL debugging on.

My project was from the template which creates a Web App to host and I finally realized that somehow the web app and the silverlight app were no longer linked. WHen I recreated the link debugging was back. Not that I need to debug becuase like you, my code is perfect the first time around! ;-)

Thursday, April 03, 2008 7:52:40 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Wednesday, April 02, 2008

I'm in SHOCK. I just learned about this option that I've always wanted in poweropint.

When I present I always print out a set of 3 per page handouts then write notes to myself about demos in the area to the right.

I often lose or throw away my notes and kick myself next time I want to do the presentation.

I came across Tip #2448 - Creating Custom PowerPoint Handouts in MS Word  on the web when I finally entered the right combination of words in google and realized that the functino exists RIGHT IN Powerpoint. In Powerpoint 2007 it's in the Publish menu.

Wednesday, April 02, 2008 4:22:39 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 

The return type of a LINQ query is an IQueryable, even a LINQ to Entities query.

Here is a screenshot of a LINQ to Entities query at design time (code is NOT being debugged).

But when the query has been processed, it's no longer an IQueryable, but an ObjectQuery.

What's going on here?

At design time, the compiler recognizes that it's a LINQ query and therefore assumes the return will be an IQueryable.

However LINQ to Entities queries are sent to ObjectServices which return an ObjectQuery, so after it's processed, it is actually an ObjectQuery.

So, since it's an ObjectQuery after all, wouldn't it be nice to leverage ObjectQuery features like MergeOptions on a LINQ to Entities query? You can!

But how? At design time, the query is an IQueryable, not an ObjectQuery and doesn't have MergeOptions.

No worries. ObjectQuery implements IQueryable.

So you can cast the LINQ to Entities query to an ObjectQuery, set the MergeOption and, as Jeffrey Palermo would say, party on the LINQ to Entities query (though he may not be likely to say that in the context of Entity Framework ;-)).

    Using context As New AdventureWorksLTEntities
      Dim query = From c In context.Customer Where c.LastName.StartsWith("S")
      Dim objquery = CType(query, ObjectQuery(Of Customer))
      objquery.MergeOption = MergeOption.OverwriteChanges
      Dim cust = query.ToList.First
      Console.WriteLine(cust.LastName)
      cust.LastName = cust.LastName.Trim & "___XYZ"
      cust = query.ToList.First
      Console.WriteLine(cust.LastName)
    End Using

Notice that I'm still performing the operations against the  LINQ query after I cast it to the ObjectQuery.

I could also have done something like

Dim custs = objquery.Execute(MergeOption.OverwriteChanges)

Thanks to Danny for reminding me about the casting! The blog post is intended to lock it into my brain.

Wednesday, April 02, 2008 3:44:46 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 

I was fiddling with compiled queries yesterday and thought I would share what I saw as results. This is anything but laboratory benchmark testing so take it for what it's worth. I did only a very simple query to start with, finding SalesOrders whose total is greater than a given number.

You can do this with Entity SQL or LINQ to Entities. Here is my LINQ to Entities compiled query:

Dim compQuery = CompiledQuery.Compile(Of AdventureWorksLTEntities, Decimal, IQueryable(Of SalesOrderHeader))( _
Function(ctx As AdventureWorksLTEntities, total As Decimal) _ From order In ctx.SalesOrderHeader _ Where (order.TotalDue >= total) _ Select order)

To interpret this, Compile's signature looks like this:

Compile(list of args, returntype)(delegate)

It takes a list of arguments and a return type then performs an operation (defined in the delegate) on the arguments. I'm defiining this compilation to recieve an AdventureWorksLTEntities instance and a decimal and the return will be an IQueryable of SalesOrderHeaders.

VB
CompiledQuery.Compile(Of AdventureWorksLTEntities, Decimal, IQueryable(Of SalesOrderHeader))
C#
CompiledQuery.Compile<AdventureWorksLTEntities, Decimal, IQueryable<SalesOrderHeader>>

For the delegate, I use a labmda epxression that says what to do with the parameters which is to build the query.

VB
(Function(ctx As AdventureWorksLTEntities, total As Decimal) _
From order In ctx.SalesOrderHeader _
Where (order.TotalDue >= total) _
Select order)

c#
(ctx, total) => 
from order in ctx.SalesOrderHeader
where (order.TotalDue >= total)
select order)

The whole query is tied to a variable

Dim myCompiledQuery=CompiledQuery.Compile(....

Then when I want to run the query, I invoke it and pass in the parameters

Dim AWEntities As New AdventureWorksLTEntities
Dim orderTotal=200
Dim orders As ObjectQuery(Of SalesOrderHeader) = compQuery.Invoke(AWEntities, orderTotal)

The first time the compiled query is run, it still has to compile, but after that it uses the results of the compilation and can swap in the parameters without needing to recreate the generated command tree.

You can see a big difference between running the query without pre-compilation and running it with the compiled query.

Brian Dawson does some more intense testing and compares LINQ to Entities to Entity SQL as well in this blog post. But I just needed to actually do it myself, rather than only reading about it.

LINQ to SQL also has compiled queries. Rico Mariani has a series of posts on this starting here.

Wednesday, April 02, 2008 9:26:41 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 

Bill Burrows has created a series of videos on MVC and is now working on a new series based on Scott Guthrie's MVC tutorial posts (which are all in C#) but using VB instead. I was surprised to find a pointer to my recent MVC post as a "rare example" of MVC with VB (and it's only one little post so I found that to be sad) so I'm happy Bill is doing these. It gives a leg up to VB developers who find it hard to try to learn something that is VERY new and convert the C# syntax in their brain at the same time.

Here's the list of topics covered

  An Overview of the MVC Pattern
  Setting up the MVC Preview Environment
  URL Routing
  Setting up New Pages
  MVC Controller Actions 
  Creating HTML in Views 
  MVC - Putting it all together

Thanks to Beth for the heads up.

ASP.NET | VB
Wednesday, April 02, 2008 8:19:32 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 

While Mother Nature played a  joke on us with 60 degree weather and high winds, followed by freezing temps, leaving a big skating rink outside our house for the poor doggies to try to manuever on... and not much left to ski on :-( , there were a bunch of silly April Fool's jokes online for us geeks yesterday.

Here are a few that I know of. Feel free to share some more.

[A New DevLife Post]

Wednesday, April 02, 2008 7:58:40 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Tuesday, April 01, 2008

Entity Framework owes a lot to the feedback of the nHibernate crew who, as Roger Jennings so aptly states, "were responsible for making the Entity Framework folks finally understand what persistence ignorance is all about".

The PI side of EF still has a long way to go, so in the meantime nHibernate continues to get stronger and stronger.

The alpha of a new version that logs over 100,000 lines of code changes was just released.

I know those guys are beyond frustrated with the current state of Entity Framework and the persistence of people like me who are curious about it and continue to share what I learn with whoever wants to listen, rather than just telling them to run away from data centric programming and join the ALT.NET wave. But what can I say. I embrace the options even if I can't become expert in them all.

Anyway, this release is a huge accomplishment and to have it be done with the dedication of what it takes in an Open Source environmnet to roll out a tool that can be used in big enterprise applications is really impressive.

Tuesday, April 01, 2008 8:24:08 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 

Highlights of this post from Timothy Ng of the VB team:

"Over the last few months, the VB and Data Programmability teams were working on fixing a performance problem with LINQ to SQL (which also manifested in LINQ to Entities). The issue was that LINQ to SQL was generating sub optimal T-SQL queries when the VB LINQ queries included filters over nullable columns."

"The good news is that the LINQ to SQL team has a fix to their code generation to recognize this pattern, and now they emit the SQL code that you would have expected to emit"

"In other words, LINQ to SQL (and LINQ to Entities - we made the same fix there) is now smart enough to pass three-value logic from VB to SQL."

Tuesday, April 01, 2008 5:02:44 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 

I'm not sure which he is more excited about! Just kidding. But considering that his wife is going to let him go to the MVP summit only 2 weeks after their first child is born, it makes one wonder!

Hey Matthieu - what's this about making fun of being a VB MVP? ;-)

Matthieu has spent a lot of time in the MSDN forums answering questions on Entity Framework. Thanks to him, I've had time to write my book while he gives the team a run for their money on answering questions. :-)

Tuesday, April 01, 2008 2:54:25 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [1]  | 
 Monday, March 31, 2008

In my blog, I write as though I am just talking and the words me, myself and I appear quite a lot.

When writing technical articles, my editors constantly have to battle the "me myself and I" becuase the article is not supposed to be a story about me. Though I really do like to share those "man, this thing was killing me until I figured out x y and z" type of anecdotal lessons.

As I am writing my book, I have been extremely careful to make the book be about YOU, the reader. Even though I desparatley want to hold your hand and lead the way, I try to be consistent with YOU and even avoid WE as in "and now we're going to do this". It takes a lot of thought to figure out how to do this without being completely impersonal because that would just not be me.

Occasionally I have written essays for CoDe Magazine's MVP Corner and I have an upcoming "End Bracket" essay in MSDN Magazine. These essays are where I get to write about me, myself and I as much as I want. Yay.

I just happened to come across a comment on a recent MVP Corner essay called Meeting Bill Gates. The comment said "Because it's natural, I had a feeling like Julia Lerman talks face to face with me. Nice"

I just love that comment because this is the way I truly love to write.

Monday, March 31, 2008 1:13:43 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 

I used to live in NY State's Hudson Valley and am always interested in what's going on there with the software community.

Some folks I know are beginning to plan for a summit to bring together software people from around the region.

They have a website with a survey (on the registration page) to help with planning the summit.

Hudson Valley Software Summit

Here is a copy of the overview on the home page:

The goal of the Hudson Valley Software Summit (HVSS) is to encourage technological innovation in the region. The area is richly endowed with creative people, many of them software developers and entrepreneurs.

The HVSS is an opportunity for these folks to network with each other and to showcase their work for others outside the immediate community, such as potentially interested parties in New York City, Northern New Jersey, Albany, and Boston.Those for whom this event is a must attend occasion include:

  • Venture capital firms
  • Technology firms
  • Internet service providers
  • Private equity firms
  • VC-backed portfolio companies
  • Angel investors
  • Professional service providers

Who work in the fields of:

  • Biotechnology
  • Communications
  • Computers
  • Internet
  • Medical
  • Peripherals
  • Semiconductors
  • Semiconductor equipment
  • Software
Monday, March 31, 2008 10:29:33 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 

The MSDN forums for data access have been restructured a little.

Entity Framework & LINQ to Entities questions:

The one which has always been under "MSDN Forums » Visual Studio 2008 (Pre-release) » ADO.NET (Pre-release)" has been renamed to MSDN Forums » Visual Studio 2008 (Pre-release) » ADO.NET Entity Framework and LINQ to Entities (Pre-release). It's still pre-release, of course.

LINQ (Released)

While there is still a general LINQ forum under MSDN Forums » Visual Studio 2008 (Pre-release) » LINQ Project General  (Yes, under Pre-Release. I imagine they don't want to lose the content or confuse people by moving the forum), the LINQ "flavors" have now been split up and are in the "Data Platform Development" section.

MSDN Forums » Data Platform Development » LINQ to SQL  
MSDN Forums » Data Platform Development » ADO.NET DataSet (This includes LINQ to DataSet)
MSDN Forums » Data Platform Development » XML and the .NET Framework   (This includes LINQ to XML)
 
Regular ADO.NET (aka "Classic")

1) The above linked ADO.NET DataSet forum is the place to go for all things DataSet.
2) MSDN Forums » Data Platform Development » ADO.NET Data Providers  
"Data platform development using classic ADO.NET (v 1.1 and 2.0) and System.Data namespace."

Monday, March 31, 2008 9:19:13 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Sunday, March 30, 2008

EFExtensions , released on CodeGallery earlier this week by EF team member, Colin Meek, has a lot of brainy goo in it. So far I've looked at the pieces that Colin has explained in his first post (first post ever) about the Extensions. While most of the extensions in the first part of his post are replicating what Object Services does, the last chunk displays the real benefit of having them at hand.

EF Function Imports can handle READ stored procedures that return existing entity sets. At first I was looking at the extensions to see if they can return random objects, but I haven't seen that yet however there's a lot to look at still. (I'm picturing a generic method that reads the columns and creates an anonymous type on the fly rather than having to go through all of the mucking with the model to make this work. Of course, this is for read-only results.)

What Colin's post shows, however is sprocs that return shaped results. A standard function import can't do this...it needs to map to a single entity type.

So by combining a few of his extensions, he is able to extract the different types from the shaped results and mimic the object materialization that happens under the covers in expected scenarios. Additionally, he is able to add these entities manually into the change tracker.

It's pretty sweet and what's funny to me is that I was trying to do something very similar to this on the same day that Colin released the extensions. I had seen them pop into Code Gallery, made a mental note and a quick blog post without digging into them yet, then a few hours later asked on the forums, "Any way to grab sets of (unrelated) entities in one database call? ". Small world, eh? Now that I have a better understanding of some of the extensions, I will have to go back and see if this does the trick.

Sunday, March 30, 2008 8:43:22 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Friday, March 28, 2008

Yep... no life.

Except for a few hours out to ski in the woods on Tuesday, I have literally been working from after breakfast to bedtime every day. I have basically been on this new schedule for a few months now and it is really unusual for me to be so focused.

Everyone warned me it would be like this.

It gets to the point where you just can't invent time and don't know what else to do but keep working until you just can't any more. One thing I won't do (and am not physically capable of doing) is cut back on my sleep.

I am definitely impressed that I can focus this well and be so driven. I just wish the pages would churn out more quickly.

When Michele Leroux Bustamante was writing Learning WCF, she told me that she felt she learned WCF at a depth which she never would have achieved if it hadn't been for the "exercise" of writing the book. I totally understand this now. Before I started, there were things that I knew well about Entity Framework, things that I had heard of but hadn't played with yet, things that I kinda knew but not really and obviously lots of things that I had no clue at all about.

So the first item in that list is easy to write about. Everything else is belaboured as I cannot bear to write a sentence unless I'm 150% sure of its accuracy.

I have had (rare) days where I wrote 20+ pages. On the other hand there have also been days (thankfully these are also rare) on which, if it weren't for screen shots, I managed to produce only 4 pages over the course of 12  hours. I have spent so much time turning over every stone, every pebble and every grain of sand in between.

It is definitely an amazing process.

The strangest and most unexpected thing is that I have actually lost weight because I'm not lingering in the kitchen or running upstairs for snacks. Or for that matter going to the store. Rich is away for a few days and the fridge is running low. I just eat what I can find and get back to work. If nothing else, I can always be grateful for losing a few pounds. ;-) Good thing I started out with plenty of extra.

And like they say about the Army, it's not a job (at least not a paying one), it's an adventure.

Friday, March 28, 2008 9:42:44 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  |