Monday, July 14, 2008

Bill McCarthy's latest garden post made me realize I hadn't taken any pics in a while so here's what's going on in mid July.

The hostas are blooming.

veggiepatch 001 

The clematis are lush.
summer visit 010

There's a lot going on in the front garden - rubekia, foxglove, daisies, mallow, astilbe, roses, russian sage and so much more.summer visit 011

The Hollyhocks are starting to open.

summer visit 014

Down by the road the menarda (bee balm) is open all along the fence. summer visit 017

summer visit 016

For some reason the daylilies along the fence haven't opened while they have opened everywhere else.

summer visit 018

I'm not sure how this sunflower got into the hanging basket, but I'll have to get it out of there soon!summer visit 028 

 veggiepatch 002

The veggie garden needs major weeding but it's lush with veggies - though we're only getting lettuce (still) and waiting for everything else to come into season. Here are some peas that are getting ready. There's plenty more but the weeds are too embarrassing, so no more pictures.veggiepatch 003

Monday, July 14, 2008 3:21:34 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [1]  | 

But it didn't make Money's top 100 list because they only looked at cities with population of 50,000 - 300,000. Here's their criteria.

Burlington is a little under 40,000.

Kathleen Dollard's home town of Ft. Collins CO was #2 on the list.

But I still think Burlington is one of the best small cities in the U.S, but since we like to keep it that way (small) maybe it's better that we weren't on the list after all. ;-)

Unfortunately, there are other factors that might kept us out of the top of that list had the population filter not excluded us. The cost of living here is higher than average especially when you put it next to the salaries.

But the quality of life is what we're here for and we all make due the best we can.

Monday, July 14, 2008 8:21:27 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [1]  | 
 Sunday, July 13, 2008

Someone posted a question in the Entity Framework MSDN forum asking for an example of overriding SaveChanges. I thought I had posted one in an early thread but couldn't find it. Nor could I find an obvious example anywhere on the web, so I thought I would put one here on my blog.

There aren't a lot of public events on the classes created from the code generated classes of an Entity Data Model. But you can override the ones that exist.

ObjectContext exposes SavingChanges.

EntityObjects expose PropertyChanged and PropertyChanging and there's a pair of these for each property in an entity. E.g. for Customer, you'll get OnCustomerIDChanged and OnCustomerIDChanging.

Because these are all partial classes, you need only to create new code files that extend the partial classes. I create a separate code file for each class.

In my sample project which hosts a model for AdventureWorks, therefore, I have a code file named AWEntities (.vb or .cs) that extends the AWEntities class.

Here's an example of that class, which does a few things to my entities when I call SaveChanges before SaveChanges actually pushes the data up to the server. In this sample, I update the ModifiedDate field for Modified Customer entities, then I do the same for new ("Added") Customer Entities as well as create new default password data.

Namespace MyAssemblyNamespace

  Partial Public Class AWEntities

    Private Sub AWEntities_SavingChanges(ByVal sender As Object, ByVal e As System.EventArgs)  _
              Handles Me.SavingChanges

      'find all entities whose state is Modified so that I can 
      '
update the Customer's ModifiedDate property

      Dim changedEntities = _
      Me.ObjectStateManager.GetObjectStateEntries(EntityState.Modified)

      For Each stateEntryEntity In changedEntities
        If TypeOf stateEntryEntity.Entity Is Customer Then
          Dim cust As Customer = cType(stateEntryEntity.Entity,Customer)
          cust.ModifiedDate = Now  'update the ModifiedDate
        End If
      Next

      'make sure new entities get modifiedDate and non-nullable fields populated
      Dim addedEntities = _
      Me.ObjectStateManager.GetObjectStateEntries(EntityState.Added)
      For Each stateEntryEntity In addedEntities
        If TypeOf stateEntryEntity.Entity Is Customer Then
          Dim cust As Customer = cType(stateEntryEntity.Entity,Customer)
          cust.ModifiedDate = Now
          'password hash cannot be null
          'for demo purposes just put a default string in there
          cust.PasswordHash = MyCustomMethodtoHashStrings("
p@ssword")
          'customer table also needs salt for hash
          cust.PasswordSalt = MyCustomMethodtoCreateRandomSaltBytes()
        End If
      Next
    End Sub

  End Class
End Namespace

(7/14: adding the base of the C# partial class as a few people have asked...)

For C#, you need wire up the event handler which you can do when the OnContextCreated event is hit.

namespace MyAssemblyNamespace
{
    public partial class AWEntities
    {
        partial void OnContextCreated()
        {
            this.SavingChanges += new System.EventHandler(mySavingChanges);
        }


        public void mySavingChanges(object sender, System.EventArgs e)
        {
            //saving changes logic
        }

    }

}

Sunday, July 13, 2008 10:27:34 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Thursday, July 10, 2008

A few months ago, Brian Dawson gave us a look at a bunch of perf tests for querying with ADO.NET and Entity Framework.

I adapted and enhanced those tests for my session at TechEd and then added even more logic to them as I dug into performance for my book.

I thought I would share some of what I found. All of the timings here are only meant to demonstrate the performance relatively between the technologies. They are hardly scientific benchmarks. In my book I've called them "backyard benchmarks".

The first set of tests is similar to Brian's in that I merely query for all of the customers in the customer table of AdventureWorksLT. That's about 450.

However, thanks to some tips from Brad Sarsfield and Bruno Guardia Robles who do performance testing on the DP team, we added an extra loop of queries to "prime the pump" so to speak and get anything like metadata loading, query caching and well as SQL Server query caching out of the way.

Here are the average times comparing different ways of querying data.

Again, read these as relative to one another and nothing else.

perfa

The EntityClient query looks funny, as you'd expect it to be faster. When the query is more complex and the data is shaped, the EntityClient performs better than ObjectQuery which makes sense to me.

This is not using any query caching  or pre-compiled queries or other advantages. I actually do a ton of those tests in that particular book chapter though.

Note that Entity Client and Object Services cache compiled queries by default (you can turn this off) which is a little different than using Compiled Queries in LINQ but has similar effect. So by default, the two Entity SQL tests are benefiting from that but the LINQ to Entities is not. So I really should either create a compiled query for LINQ to Entities and LINQ to SQL or turn query caching off for the two Entity SQL tests, because that's not completely fair.On the other hand, these *are* the defaults.

But what I found really interesting were updates.

There are a lot of ways to update data with ADO.NET. I chose to use DataAdapters since calling DataAdapter.Update is relative to calling context.SaveChanges. Here I queried those same 450 or so customers, edited each one, added 10 new ones then updated the database. I also was sure to clear out the 10 new records from the database after each iteration of the tests was complete. I didn't happen to do any deletes in this test.

I also did one DataAdapter.Update using UpdateBatch, just to compare.

In all cases I am starting the stopwatch, performing the update, then stopping the stopwatch. These times are the average of my 100 iterations of each test.

perfb

That is not a typo next to LINQ to SQL. I have not dug into why this is so different, but I had been told that EF was much faster than LINQ to SQL for updates. I had to see for myself. Bruno says this looks about right, but he's going to double check my code to make sure I didn't do anything completely wacky. And if I did it wasn't intentional.

But I was also interested to see that Object Services was also faster than DataAdapter.

I'm not trying to make a point here...just an observation because I have never seen these comparisons made before.

For all of these methods there are a lot of things you can do to improve this performance, not only in code but on the servers. And some server tweaks might benefit one method but not another. These tests are just using all defaults and gives me a stake in the ground. Now if I didn't need to actually finish my book, I could just keep at it which would be fun and interesting. But it wouldn't be so fun when Tim O'Reilly comes knocking on my door wondering where the heck my book is!

Thursday, July 10, 2008 4:07:06 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [4]  | 
 Wednesday, July 09, 2008

At Remix 07, I got an intro to the fact that Robotics Studio has APIs in there that are being used for some amazing projects that have nothign to do with robots. Last month I had a chance to talk with the man who heads up the Robotics Division at Microsoft and then coincidentally discovered an article on the same in the June 2008 MSDN Mag. Read more...

[A New DevLife Post]

Wednesday, July 09, 2008 10:28:19 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Friday, July 04, 2008

I definitely want to hear Roger Jennings' story! Roger, your turn!! :-)

Friday, July 04, 2008 7:53:04 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [1]  | 
 Thursday, July 03, 2008

I've been called out by Shawn Wildermuth to answer a bunch of questions about how I got started in programming, etc. I've done that over here and called out 5 more folks as well.

[A New DevLife Post]

Thursday, July 03, 2008 2:50:24 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Sunday, June 29, 2008

Sorry, this has nothing to do with Entity Framework. :-)

This is about garden slugs! I've been having some problems with the slugs decimating the Romaine in my garden. Since my husband wouldn't let me use any of his fancy beer to lure them away, I used the next trick I learned about - "over ripe" yogurt.

I put it in a small yogurt container, dug a whole in the corner of my garden and placed the container in there so that the top was level with the ground.

Yesterday I went out there and it looked like every slug in Vermont had heard about the awesome yogurt being served up on Moody road. They were coming out of the tall grass surrounding the garden and I think there must have been 50 there.

Whoa - big mistake. Now all of those slugs know about my romaine! I probably should have put that yogurt a bit farther from the garden.  It's similar to when people very cleverly buy those "bag a bugs" to lure Japanese Beetles away from their flowers. But the scent in those sacks is so powerful that it draws Japanese Beetles from far away. We've trained our neighbors not to use them. So far so good this year - the roses are blooming and actually sticking around!

I went out this morning to take a picture of the slugs because it was so bizarre and was surprised to find they were all gone. It was like a big frat party had just dissipated and to add to the image, there were two slugs that were slowly slugging there way away from the yogurt container back into the weeds that surround the garden.

The real goal was that they were supposed to fall in there and drown (I know - murderer! All for a head of lettuce!) but instead they drained the yogurt and headed off. At least the mass of slugs wasn't attacking the lettuce. But I'm sure they'll be back!  EEEEEW.

Sunday, June 29, 2008 11:06:48 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [1]  | 

After appying SP1 on one of my development machines, I got a COM Interop error when opening up SQL Server Management Studio. It took a few minutes to find the correct search terms on the web, but I found the simple fix to the problem pretty quickly. Read more here...

[A new DevLife post]

Sunday, June 29, 2008 10:57:38 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Friday, June 27, 2008

Apparently not everyone in the world has been conscious that today is Bill Gates last day working full time at Microsoft. My sister thought that the "moving on" story she heard on NPR was an obit... read more

[A New DevLife Post]

Friday, June 27, 2008 7:19:27 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Thursday, June 26, 2008

I've seen this quote in many of the recent discussions of the evils of Entity Framework.

In the comments to Sebastien Lambla's, blog post, Danny Simmons explains:

The goal is not one model to rule them all. The goal is unifying the way you specify models in many tools to be the same. That way you can leverage your learning across many things. That way if you WANT to reuse some of your model in multiple places you can, but the real thing is that it's absolutely ridiculous that I have to do essentially the same task in completely different ways when I want to build a model for my objects that talk to the database and another model (maybe with different contents but the same idea of a model) for my reporting and another one for whatever else. We're trying to eliminate the differences in experience and learning required for the parts of these tasks that are very much the same.

I thought it was worth surfacing.

Thursday, June 26, 2008 8:42:16 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
Thursday, June 26, 2008 3:29:44 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 

If you live in northern Vermont and you have any interest in SQL Server, you'll want to attend tonight's VTSQL meeting. It's their official SQL Server 2008 Launch event, with gobs of swag provided by Microsoft and pizza sponsored by MyWebGrocer.com. Laura Blood and Roman Rehak "will be giving an overview of some of the most interesting new features arriving with SQL Server 2008.  We can’t cover everything, but hope to provide you with some insights on what new functionality you can look forward to."

6pm to 8pm at Competitive Computing.
354 Mountain View Drive
Colchester, VT 05446

More info and directions at www.VTSQL.org.

Thursday, June 26, 2008 10:22:23 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [3]  | 

The Entity Framework - don't get fooled in what is wrong about it

I guess it's better than calling myself a "self-congratulatory, self-proclaimed, egotistical doofus". ;-)

(In case the reference doesn't make sense, Sebastien has since modified his post so that the word "fooled" no longer links to my blog...)

Thursday, June 26, 2008 7:55:44 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [1]  | 
 Wednesday, June 25, 2008

Dinesh uses humor (laced with a little well deserved sarcasm) in response to "the sky is falling because Technology X doesn't fit my way of programming" ....

Design of LINQ to SQL - What was I thinking or was I?

Wednesday, June 25, 2008 6:40:49 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [4]  | 
 Tuesday, June 24, 2008

A few months ago I came across this great interview with Jimmy Nilsson where he is talking abot LINQ and Entity Framework. I love what he says about LINQ - that it's a beatiful thing and it's small & compact. And I'd been very curious to know what Jimmy thought of EF since I missed my chance to meet him and ask directly when I went to Stockholm. The most memorable thing he said is that it is "very big". Indeed it is. And of the things he didn't like about SQL, the most critical was the lack of value objects (aka, thanks to Roger, what we know as complex types in EF). With EF it was that it comes so deeply from the data world and the lack of PI. Here he calls IPOCO the "anti-PI". While I don't have time to set EF aside and sit down and really learn about Domain Driven development as  well as the slew of ORMs out there, I do try to grab what I can when I can and I this particular video, with Jimmy's soft-spoken contemplative way of addressing these topics, has definitely stuck in my mind.

In addition, Jimmy talked about Eric Evan's book "Domain Driven Design" and that it "is like poetry". I loved that and immediately went to find some text from it to understand what he meant and I totally agree. It's not like a typical technical book to begin with because it is all concept and written from the heart. It really made me look back at how I was "speaking" when writing my book which is very different than how I write, for example, here in my blog. In the book I am trying to explain technical concepts, how to, how to code, what does this mean, what does that mean, how does this thing work, etc...and it feels much more formal. As I go back and review what I've written, I hope to loosen it up a bit. And eventually, I'll get to read Eric's book for content, not just writing style, but for the time being I need to stay focused...

And in the meantime, I'm really excited that Jimmy & Eric are both part of the advisory group for v2 of Entity Framework.

Tuesday, June 24, 2008 4:54:34 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [2]  | 

Anyone who knows me knows that I just LOVE being in the middle of a controversy. Well, that's a lie. I sure know how to pick'em, though, eh?

I have to deal with java and open source people (many who I am friends with, respect and admire) harassing me because I use Microsoft products.

I have to deal with C# developers (many who I am friends with, respect and admire) harassing me because I code with VB mostly.

Now I have to deal with Domain Driven Developers (many who I am friends with, respect and admire) harassing me because I have been busting my ass learning about Entity Framework and trying to share what I know because there are going to be a lot of people who will have to learn how to use it.

So now there's this no-confidence vote to ... I think just counter all of the information about what EF is and can do to vocalize where it's failings are if you have a particular programming style which is not supported in v1 (though are targetted for v2 and important to the EF team) and to take the EF team (which is part of the Data Programmability team, which is part of the SQL Server team) to task for creating a data-centric framework. However, the way the petition is laid out is to list it's failings to be sure that nobody gets "tricked" into using Entity Framework. Not to say the only problems are from the perspective of Domain developers, or nHibernate users or those who need Persistence Ignorance. I struggle with it too, but I just don't have the same needs as those that are listed in the petition.

I was happy to see that the Entity Framework team has responded very quickly. This responsiveness is new for them, and a new part of their recently announced transparent design for v2 which they adopted from the Astoria team.

Tuesday, June 24, 2008 2:53:45 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [2]  | 
 Monday, June 23, 2008

With the exception of this past Saturday (which I took advantage of by riding my bike 50 miles to our friends' house on the lake), this has been what the forecast has looked like for the past 2 weeks. Unfortunately, this particular view is for the upcoming week.

I tried to sneak in a little ride this afternoon, but got caught in the rain.

Of course, it's not like we're flooded out, so I can't complain. We live up on a hill so we're more susceptible to the lightning than the rain.

Monday, June 23, 2008 7:13:10 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Wednesday, June 18, 2008

I have no idea when this went on to Amazon, but it's there now. I STILL don't have a cover which is frustrating. And Amazon seems to have given me some extra time to finish my book! The "about the author" seems funny to me. I guess since, unlike some people, I don't have 80 books under my belt (LINQ to Dummies is #80 for John), or even one, there's not much to lean on here.

 

I think it's going to be a bit longer than 456 pages, but hell, with that big discount, I better find another day job! I think that will translate to about $1/book that goes towards my royalties! And I doubt that the book will hit Amazon's top 10 list (of all categories) like Bill, Scott & Devin's ASP.NET book which has already been reprinted numerous times!

Wednesday, June 18, 2008 3:39:42 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [4]  |