Monthly Archives: April 2008

What’s in a name?

This week I had to make a very difficult decision. It will make you laugh, but really, it was hard.

I had to decide if my book will say “Julie Lerman” or “Julia Lerman”.

After a LOT of deliberation, I decided to go with my grown up name: Julia Lerman. Which means that any searching on Amazon or whereever for “that book by Julie Lerman” won’t find it.

An extension method for visualizing ObjectStateEntries

EntityStateObjects, to me, are one of the most important little pieces of the EF puzzle. IT is the EntityStateObject that maintains all of the critical info for change tracking. But it’s hard to get the big picture of what’s going on in there when debugging because all of the important stuff is delivered through methods, not properties.

I wanted so badly to write a debugger visualizer for them but they are not serializable (big pout) so instead, I wrote an extension method that uses a ConditionalAttribute to ensure it doesn’t pop up during run time. It’s for my book but I didn’t want to hold onto it until October when the book should be published.

Since it’s not a Debugger Visualiser, I refer to it as a DebugTime visualizer. 🙂

Here’s what my ObjectStateEntry Visualizer looks like in action:

All of the info is pulled from the ObjectStateEntry. At the top it tells the fully qualified name of the type of the object being inspected as well as the object’s EntityState.

Then I use the various methods of the ObjectStateENtry to get the Original Values, the Current Values, the names of the fields and a list of the names of the modified fields.

All of this data I feed into the grid.

If the object is detached, then there is no ObjectStateEntry and the visualizer shows this message when you try to run it:

So enough with the screenshots. Here’s the code. And here’s a collection of important punctuations for you C# programmers who feel a need to translate

[ ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;  ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;  ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;  ; ; ; ; ; ; ; ; ; ; ; ; ; ;]

 

Imports System.Runtime.CompilerServicesImports System.Data.Objects'NOTE: The objects in use here are not serializable so they can't be used'in debugger visualizers. Instead, you'll need to use them directly, but you can 'give them a debug attribute so they are only available during debug mode.<Extension()> _Public Module Visualizers<ConditionalAttribute("DEBUG")> _<Extension()> _Public Sub VisualizeObjectStateEntry(ByVal eKey As EntityKey, ByVal context As ObjectContext)Dim ose As ObjectStateEntry = NothingIf Not context.ObjectStateManager.TryGetObjectStateEntry(eKey, ose) ThenWindows.Forms.MessageBox.Show("Object is not currently being change tracked and no ObjectStateEntry exists.", _
"ObjectStateEntry Visualizer", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Warning)ElseDim currentValues = ose.CurrentValuesDim originalValues = ose.OriginalValuesDim valueArray As New ArrayListFor i = 0 To currentValues.FieldCount - 1



'you can get from the ObjectStateEntry into the MetaData which actually comes from the EDM
Dim sName = currentValues.DataRecordInfo.FieldMetadata.Item(i).FieldType.NameDim sCurrVal = currentValues.Item(i)Dim sOrigVal = originalValues.Item(i)
'nothing like a little LINQ query to find some infoDim changedProp = (From prop In ose.GetModifiedProperties Where prop = sName).FirstOrDefaultDim propModified As StringpropModified = If(changedProp = Nothing, "", "X")

'the funky property naming in this anonymous type is to get around a wierdness with
'LINQ databinding that only occurs in VB - it alphabetizes the fields
valueArray.Add(New With _
{._Index = i.ToString, ._Property = sName, .Current = sCurrVal, _
.Original = sOrigVal, .ValueModified = propModified})NextDim frm As New debuggerFormWith frm.DataGridView1.DataSource = valueArrayEnd Withfrm.lblState.Text = ose.State.ToStringfrm.lblType.Text = ose.Entity.ToStringfrm.ShowDialog()End IfEnd SubEnd Module

The form has no code, just a few controls:

I created an assembly for my Entity Framework extension methods and just reference the assembly anywhere I want to use it.

Then when I want to use it, I call it against the EntityKey of an Entity Object:

context = new AWModel.AWModel.AWEntities();cust = context.Customers.Where(c => c.CustomerID == 223).First();cust.CompanyName = "JULIE COMPANY";cust.EntityKey.VisualizeObjectStateEntry(context);

This has been an enormously useful tool for when I have been presenting as well as just working.

Enjoy!

Sneak Peek at the EntityDataSource Control

Along with a few hundred other DevConnections attendees, I got a sneak peek of the EntityDatasSource control on Monday during Danny Simmons’ Entity Framework Architecture session.

 

I think I paid more attention to the control than what Danny was saying because I was desperate to see how it was set up.

 

Before digging in though, I also wanted to note that the UI of the EDM Designer looks really pretty. I noticed that the association lines/connectors looked different; the whole thing was cleaner looking (were the association names gone?) and the Entities have their own little representative icon now. I can’t wait to see this in more detail.

 

The EntityDataSource wizard identifies EntityConnections in the config file and offers those to as choices for building the data source from. Once that is selected, the EntityContainer is also identified, offering the list of EntitySets from the container to use for the data source.

 

Like the LINQDatasource, you have the option of selecting all of the properties at once or selecting specific properties which will perform projection. Like the LINQDataSource, if you project properties, then you won’t get a full type back and the data will not be updatable.

 

There was a drop down list below the one where you choose which EntitySet you want to work with but I don’t recall what it’s name was. Danny did not drop it down. All I can think of that might be there (hopeful) is derived types since they don’t have their own EntitySet.

 

Although I don’t remember seeing it during the session, Danny did say that you can choose to eager load related data in the same way that you can with the Include method. I don’t know how this is done or if it will impact updating, but I don’t know why it would.

 

Like the LinqDataSource,  the EntityDataSource performs server side paging, and it does client side caching – of current AND original data. The original data is not stored as complete objects, but the minimal data necessary to reconstruct state when it’s time to update. Updates happen, like any other data source, one at a time. So you have to pick an item, edit it and update it.

 

 I’ve got some of my own examples of using series of entities in web apps which are very different from this. My solution, however, is aimed at a different scenario. Where the EntityDataSource is more scalable because of the server side paging and the fact that it is not caching full objects, my solution allows the user to do a bunch of edits then save them all at once. I keep the objects in the client side cache (I know – horrors! – but it’s an option for a developer to choose) and a collection of original objects cached on the server, though it’s an application cache, not a session cache.

 

Seeing the EntityDataSource has already given me some ideas of taking my solution and making it more scalable without losing the benefit of the bulk editing.

 

I can’t wait to get my hands on the new bits!

DevTeach is coming to Toronto Ontario in just a few more weeks!

I COPIED THIS ENTIRE BLOG POST DIRECTLY FROM GUY BARRETTE’S BLOG and made one little edit! So shoot me! 🙂
 

If you’re living in Toronto and don’t attend DevTeach, [Guy Barrette says he’s] gonna beat you up and force you to code in Clipper for the rest of your life.  Seriously, DevTeach has one of the greatest speakers lineup of all the .NET conferences.

Honestly, where can you hear, see, talk to, describe your problems (IT/Dev related or not) and have a beer with these guys/gals?

Scott Bellware Benjamin Day Oren Eini Cathi Gero Barry Gervin The one and only Kate Gregory YAG The Zen of Scott Hanselman Moi Beth[mond] Massi Kevin MacNeish Roy Osherove Rodman Partyboy Palermo Paul [Yes, it's true. I live on a boat] Sherriff Joel Semeniuk Richard Campbell Peter DeBetta Don Kiely of the Alaska Keilys Bill Vaughn Adam Machanic Carl Franklin Rob Windsor Jim Duffy

And that’s only half of them!!!

Need more reasons?

Keynote by Scott Hanselman, Microsoft
Scott Hanselman is one of the most prolific, renowned and respected blogger (
http://www.hanselman.com) and podcaster (http://www.hanselminutes.com) about technologies. Scott is a hands-on thinker, a renowned speaker and writer. He has written a few books, most recently with Bill Evjen and Devin Rader on Professional ASP.NET. In July 2007, he joined Microsoft as a Senior Program Manager in the Developer Division. In his new role he’ll continue to explore and explain a broad portfolio of technologies, both inside and outside Microsoft. He aims to spread the good word about developing software, most often on the Microsoft stack. Before this he was the Chief Architect at Corillian Corporation, now a part of Checkfree, for 6+ years and before that he was a Principal Consultant at STEP Technology for nearly 7 years.
http://www.devteach.com/keynote.aspx

Silverlight 2.0 workshop
For the first time an independent conference is having a workshop on Building Business Applications with Silverlight 2.0.  Join Rod Paddock and Jim Duffy as they give you a head start down the road to developing business-oriented Rich Internet Applications (RIA) with Microsoft Silverlight 2.0. In case you just crawled out from under a rock, Microsoft Silverlight 2.0 is a cross-browser, cross-platform, and cross-device plug-in positioned to revolutionize the way next generation Rich Internet Applications are developed. Microsoft’s commitment to providing an extensive platform for developers and designers to collaborate on creating the next generation of RIAs is very clear and its name is Silverlight 2.0. In this intensive, full-day workshop, Rod and Jim will share their insight and experience building business applications with Silverlight 2.0 including a review of some of the Internet’s more visible Silverlight web applications. This workshop is happening on Friday May 16 at the Hilton Toronto.
http://www.devteach.com/PostConference.aspx#PreSP

Bonus session: .NET Rock host a panel May 14th at 18:00
This year the bonus session (Wednesday May 14 at 18:00) will be a panel of speakers debating the Future of .NET. Where is .NET going? How will new development influence .NET and be influenced by .NET? Join Carl Franklin and Richard Campbell from .NET Rocks as they moderate a discussion on the future directions of .NET. The panellists include individuals who have strong visions of the future of software development and the role that .NET can play in that future. Attend this session and bring your questions to get some insight into the potential future of .NET! This bonus session is free for everyone. Panelists are: Ted Neward,Oren Eini ,Scott Bellware
http://www.devteach.com/BonusSession.aspx

Party with Palermo, DevTeach Toronto Edition
Jeffrey Palermo (MVP) is hosting Monday May 12th in Toronto is acclaimed “Party with Palermo”. This is the official social event  kicking off DevTeach Toronto. The event is not just for the attendees of Toronto it’s  a free event for everyone. It’s a unique chance for the attendees, speakers and locals  to meet and talk with a free beer.   The event will be held at the Menage club  location and you need to RSVP to attend. Get all the details at this link:
http://www.partywithpalermo.com/

Make sure that DevTeach comes back to Toronto.  Register right now for this year’s conference.

Generating proxies with Astoria’s WebDataGen under Vista UAC

This bit me in the butt … TWICE!

When using WebDataGen so that you can get a proxy class for an Astoria data service, if you are running under UAC, the output file will NOT get created, however the tool reports that the file was created successfully.

I spent a lot of time trying to find the file or figure out what I was doing wrong.

Then a week later, when it was late at night and I was sick so my brain was a little foggy, I had to create another proxy but totally forgot the pain I had gone through previously. It was an hour before I finally remembered that I had to run the command window as admin.

So word to the wise….and I should probably make a not of this in the forums.

Red Carpet Speaker Lounge

I left DevConnections for the Orlando airport and when I got there had another hour and a half before my flight, so headed to the Red Carpet Club. I walk in and as I go to sit down I see Dr. Neil. As I got closer to where he was sitting, there was Michele Leroux Bustamante and Mark Miller. A half hour later, in comes Tim Huckaby. So we’re all here with our laptops open, chatting and dare I say – gossiping. If you call talking about how cute someone’s baby is “gossip”, then I guess that would be the case.

 

Live from DevConnections

I’ve been in Orlando at DevConnections for the past few days. I’ve been a little under the weather which has made it a little rough around the edges for me, but I’m surviving. While it was a bit of a challenge to present a full day workshop with a nasty chestcold, this was nothign compared to Kathleen Dollard who gave a Workflow workshop in the room next door with bronchitis. She knew she was sick but didn’t know how sick until I dragged her to a clinic that night and discovered she had a high temperature and bronchitis. Poor thing. She’s surviving and did talks today and has more tomorrow.

I met a young programmer named Scott Pio at the attendee party tonight who has been writing some great blog posts about being at DevConnections  on http://spoiledtechie.com/ — the experience as well as the sessions he has attended. It’s so fun to meet young developers who are just so ready to burst with their excitement about technology. It’s his first conference and I think the first time he’s been somewhere where the term “geek” is actually a complement! Definitely check out his blog and especially his posts about DevConnections!

Finally! United Red Carpet Club has free wi-fi!

Hip hip hooray.

My only trip so far in 2008 was on USAirways, so I hadn’t realized this until just now as I’m stuck in Dulles for 3 hours because  – oh shock! – my flight from Burlington was delayed and I missed my connection by minutes. As we landed, I saw my plane to Orlando sitting at the gate. I hoofed it down the hallway with my backpack on and my carryon in tow (not great fun in Teva’s), arrived breathless to learn that it had just left. Now why don’t they get the fact that I’m on a connecting flight – one of their own – and just pulling into my gate and just wait another 2 minutes?

Anyway, at least I had the nice surprise of the free wireless to go along with teh carrott sticks and packaged bites of cheese they have for us here in the lounge. Oh, how it makes me miss the Lufthansa and Ai Canada lounges with their real food and (even though I don’t take advantage) local beer on tap!