All posts by Julie

Nathan Myhrvold, Microsoft Research founder, in The New Yorker

This week’s The New Yorker issue is focused on invention and there is a really fun read on Nathan Myhrvold, Intellectual Ventures, dinosaurs, Alexander Graham Bell and more called In the Air.

Having been on the nosy Lake Washington cruise which goes by his house, Gates’ and others, it was funny to read his wife describe their house as “the place in the sci-fi movie where the aliens live”.

The article is focused on the process of invention and highlights some of the amazing brainstorming sessions that Myhrvold has with IV participants (including Bill Gates) who’s goal is to patent 1000 new inventions a year. They are at about 500 /year now, dealing with everyting from medicine to nuclear fision.

Entity Framework’s Golden Rule and its Platinum Rule

I have found myself explaining this in conference sessions so I thought I would write it down in my blog.

Entity Framework has a Golden Rule. Though shalt not do nuttin’ that the developer has not explicitly told you to do. The lack of implicit lazy loading is one of the more notable (and hotly contested by some) example of this.

But one day when I was coding, Entity Framework did something that I did not ask it to do. I emailed Danny Simmons to tattle on the API. But Danny explained something to me about RelationshipSpan that needs to override the Golden Rule.

I now call it the Platinum Rule. (I learned this pecking order from American Express).

The Platinum Rule is that an object graph (for example when a customer is attached to an order which is attached to some line items) must be completely in or completely outside of the ObjectContext.

The way I discovered it was that I had a Customer that was being change tracked by an ObjectContext.

I created a new order and attached the order to the customer.

But I did NOT add or attach the order to the context.

Yet, the order was suddenly within the context and being change tracked. Why? Because of the Platinum rule. By attaching the order to the customer, I was creating a graph. Since the graph can’t have some of its objects in the context and some of its objects out of the context, it has three options.

  1. Don’t allow the objects to be connected. (Now wouldn’t that tick you off?)
  2. Pull the customer out of the context. (Now wouldn’t that really tick you off?)
  3. Pull the order INTO the context.

Okay, works for me.

So this is the same rule that confuses people when they have an object graph that is IN the context and they detach one of its objects. That object leaves the context and “broken”off of the graph. So if you called context.Detach(Customer), then the customer is detached but the Order and its Line Items are still in the context.

You can no longer traverse from the Customer to the Order or from the Order to the Customer.

On the flip side, if you have an object graph that is not being change tracked  – the whole package, Customer, the order and the details and they are all attached to one another, if you attach any one of them to the context, the whole kit n’ caboodle gets pulled into the context – because of the platinum rule.

Another Domain Developer’s view of Entity Framework and Lazy Loading

Like Jeremy Miller, who has Transparent Lazy Loading for Entity Framework on his Christmas Wish List, Timothy Khouri does not like the fact that Entity Framework doesn’t support Lazy Loading. However, since he really likes Entity Framework, he wrote some code that will enforce Lazy Loading for him. Entity Framework promises not to do anything you don’t explicitly tell it to do, so Timothy found a way to keep telling EF to do this for him because that’s what he wants.

After looking at LINQ to SQL’s Lazy Loading and then bumping into Entity Framework’s explicit Deferred Loading, then sorting things out so he understood not only how the two are different but why, he shares his lesson and his workaround in this article: Entity Framework and Lazy Loading

Delete Stored Procs and Navigations in the Entity Data Model

Entity Data Models have a lot of rules. They are necessary for the integrity of the model, though if you are not familiar with depth of EDMs and *why* these rules exist, many of the mapping rules may seem to make no sense when it comes trying to implement them. This gets hairy when you are mapping stored procedures. Roger Jenning’s solution is to create stored procedures that will map properly, rather than suffer wtih the ones that already exist.

The first level of using Stored Procedures is that they work very easily for existing entities that are simple, have no EntityReferences (these involve Foreign Keys) , don’t involve inheritance and map directly to a single table in your database.

The next is stored procs that map nicely to entities which don’t involve inheritance but if your entities have any relationships, you will probably run into a wall with a delete procedure. Here’s why.

Stored Procs become Functions in the Entity Data Model. If you want to use these functions rather than the dynamic SQL that Entity Framework will create, it’s an all or nothing scenario. You need to map an Insert, and Update and a Delete. (Read procs doesn’t come into play here). There are plenty of blog posts and other resources on how to do this including this tutorial I wrote for the DataDeveloper.net site.

If you have a relationship in your entity, you can map that easily enough to a foreign key parameter in the function mappings and this makes sense with Inserts and Updates. With deletes, generally you only have a primary key (eg ContactID) as the parameter for the stored procedure. But here is where the EDM rules come in to play. A foreign key value that is used in a stored proc, would in most cases map to the EntityKey of a navigation property.

In other words, if you have a stored proc to insert SalesOrders, that procedure will have a parameter for CustomerID. The Order Entity this is mapping to has a relationship to the Customer entity and contains a Customer navigation property. The mapping therefore would link the CustomerID paraemter to Order.Customer.CustomerID.

By doing this, you are involving the association that exists between the Customer entity and the Order entity.

The EDM rule is that if you are involving an association in ONE of the function mappings, you have to use it in ALL o the function mappings.

Therefore a stored proc to delete an order, which only has an OrderID parameter will need also to have a CustomerID parameter because you are required to map SOMETHING to the Customer entity.

This then breaks a possible rule. It means you need to go to the dba and beg them to add this parameter into the stored procedure even though it doesn’t get used.

The alternative is to just go in and modify the SSDL to trick it into thinking that that parameter exists which will make the model happy and the database won’t care at all. IT doesn’t ever really get used.

So if the actual stored proc is

PROCEDURE DeleteOrder

@OrderID int

AS

DELETE from ORDERS WHERE OrderID=@OrderID

and the original function in SSDL is

 <Function Name=”DeleteOrder” Aggregate=”false” BuiltIn=”false” NiladicFunction=”false”
            IsComposable=”false” ParameterTypeSemantics=”AllowImplicitConversion” Schema=”dbo”>
     <Parameter Name=”OrderID” Type=”int” Mode=”In” />
 </Function>

You just need to add a new parameter to the SSDL

 <Function Name=”DeleteOrder” Aggregate=”false” BuiltIn=”false” NiladicFunction=”false”
            IsComposable=”false” ParameterTypeSemantics=”AllowImplicitConversion” Schema=”dbo”>
     <Parameter Name=”OrderID” Type=”int” Mode=”In” />
     <Parameter Name=”CustomerID” Type=”int” Mode=”In” />
 </Function>

This is all fine and good until you need to update the model, because the SSDL will lose all customizations.

I keep my customizations listed in a separate text file so that if I must update the model,  I can replace them.

It’s not pretty, but when I don’t have a lot of customizations, I will choose this over bugging the dba. Okay, in my world, I’m the DBA (how pathetic is that) but I’m trying to think about enterprise developers and real DBAs.

I started out wanting to write about dealing with stored procs for entities that are inherited, but I guess that will have to come later!

Our .NET Community

I was perusing Chris Williams’ blog over on GeekswithBlogs.Net. I met Chris many years ago through INETA and in person at an INETA User Group Leader event. Chris ran the user group in Charleston, South Carolina and has since moved to Minnesota where he has survived his first winter with all of his fingers and toes intact. He is a really nice, unique and memorable guy (okay the tat’s definitely help him stand out).

While looking at his blog, I saw a post of photos from a funny ad that apparentlyly reminded Chris of D’Arcy Lussier, a a wild and crazy guy (also a GeekswithBlogs blogger) who lives in Winnipeg (where I think you need to be a little wild and crazy to survive), and probably laughs at Chris’ mumblings about the cold weather in Minnesota. D’Arcy also is a user group leader and I see him frequently at the DevTeach events in Montreal and look forward to seeing him at DevTeach next week in Toronto where I plan to goad him into a his own Meatloaf imitation. (I didn’t realize that the dad in the commercial really is Meatloaf!)

What struck me when I saw the photos and Chris’ comments about them was that here are two guys who have a lot in common and are clearly good friends who may never have met if it weren’t for INETA and the .NET blogging community. I know it may seem obvious that of course they would find each other, but it’s not a given. These resources were only just starting up 6 years ago, so they are relatively new.

It really made me stop and think when I saw that blog post and made me happy and very proud of the community that we have all created.

TechEd Schedule is filling up

And I haven’t even had a chance to look at any presentations yet.

Here’s what’s on my schedule so far.

  • Monday morning – speaker training
  • Monday afternoon – INETA User Group Leader Meeting (yay!)
  • Monday evening – Speaker dinner
  • Tuesday 1-2: Vista Ask the Experts Booth demoing Annotation in Silverlight
  • Wednesday Lunch: Women in IT Panel (yay)
  • Wednesday 2:45: Birds of Feather “Is Entity Framework right for your application?”
  • Wednesday 7pm: Birds of Feather with Steve Smith: “Going Solo”

(and the real reason I’m going)

  • Thursday 10:15 – 11:30 am  Advanced Entity Framework: Take Charge of Object Services
  • Thursday 2:45 – 4:00pm Microsoft .NET Framework 3.5 Data Access Guidance

And then as soon as I finish my session I have to run to the airport to catch a 6:45 flight. (and miss the attendee party, duh)

So this is starting to look like one of the conferences where I don’t get to go to sessions. Because all of the rest of the time, I’ll need to be in a quiet place practicing my sessions and writing my book!

The Bob & Chris (and now Jim, too) Roadshow returns to Burlington May 22

Don’t pencil it in; ink it in!

May 22nd at Vermont Technical College in Williston from 9am to 4pm.

You may notice that May 22nd is on a THursday. I will put money on the fact that Chris scheduled this so that he can go to Bove’s. THe last few times he hit town at the beginning of the week, but Bove’s is closed on Sundays and Mondays and I think I heard the sobs all the way down here in Huntington. Thankfully, he discovered The Skinny Pancake down by the water front and is now a fan of that resto, too!

Read more details about the roadshow on Chris’ blog!

Spring Diary!

 

spring 002 (Custom)

spring 003 (Custom)

Veggie garden’s ready in case I ever get ready. I did already put some lettuce and peas in on the left.
Only super hardy stuff goes in now. We can’t do our regular planting (tomatoes etc) until after Memorial Day.
Short growing season in Vermont.

spring 004 (Custom)

Compost is ready and waiting.

spring 005 (Custom)

Lupine are coming up. They are SO hardy.There are hundreds of them in the front field. Looks amazing in early June!

spring 006 (Custom)

The front garden has already got blooms in it and everything else is growing like mad. 

spring 007 (Custom)

And the winner is…. the first tulip opened today.

spring 008 (Custom)

Columbine will be in bloom in another month. They spread on their own so there’s a bunch of this.

spring 009

This lilac is making flowers for the first time this year. It’s neighbor is still flowerless. Maybe next year.

spring 010

Lots of Lilies. There are also miles of bee balm along this fence as well as berries and lupine and a very hardy delphinium.

spring 011 (Custom)

Is this bucolic enough? I love this ancient Maple tree down by our mailbox.

But best of all, my favorite flowers are STILL here

tasha may 2008

Tasha, now 14 1/2 which is insanely old for a Newfie.

spring 017 (Custom)

And Daisy, the puppy in the house. She’s 13 1/2.