Striving

I heard a long time ago that there are three types of people: apathetic, mediocre, and excellent. I would rather say there are two types: those who are striving for excellence and those who are not striving.

Of the folks striving for excellence, there are again two types: those doing it for themselves and those doing it for others.

Those striving for excellence for themselves are motivated by something like fame or power or acceptance, but those striving for excellence for the sake of others realize that their hard work, dedication, education, and persistence can make a real difference in helpingothersto grow.

Whatever your place in life, whatever your training or your role or your level, you most certainly have opportunity to apply effort for the sake of others.

Troubleshooting Your EF Code First Mapping

Here’s the scenario. You’re a developer and a you create a great set of objects and relationships between them that perfectly expresses the structure of your prospective application. You want to just tell your code to go ahead and create a new database (or map to an existing one) that matches your model and allows you to store the data?

So you do this with EFCF and all is well. Except that occasionally you tweak your model and run into a mapping error and all is not well. EF has a hard time communicating to you what exactly is wrong and can give some pretty obscure exception messages, and you can spend a lot of time (personal experience) tracking down what you’ve done wrong.

The error I just ran into is this one: “Type Address_Country is not defined in namespace PEP.CIM.Entities.Mapping (Alias=Self).” Huh? I know that I just tried to create a Country navigation property on my Address entity so I have a general idea of where my error might be, but after a double check of my code I can’t see how it’s any different from my other relationships that are working fine. So what’s the problem?

I stumbled upon a great way to troubleshoot these kinds of issues, though… the Entity Framework Power Tools (at CTP1 as I type). I have used this tool countless times to reverse engineer a database into good-lookin’ C# code, but today I used it for something else. When the tool is installed (and you have EF referenced in your project!), you can right click on your context and get a few options under the Entity Framework menu item.

In my case, I was able to use View Entity Data Model XML and then look through the resulting XML for the Address_Country relationship. I fairly quickly discovered that I had NavigationProperty elements for my Address_Country but I didn’t have a coresponding Association (as I did for my working relationships). This lead me back to my fluent mapping statement…

HasRequired(t => t.Country).WithMany(t => t.AddressesByAdrCountryCdvId).HasForeignKey(t => t.AdrStateProvinceCdvId); HasRequired(t => t.State).WithMany(t => t.AddressesByAdrCountryCdvId).HasForeignKey(t => t.AdrStateProvinceCdvId);

where I discovered that I had made a grievous copy paste error. As you can see, I’m attempting to add mappings for Country and State, but it’s all wrong. Each is mapping AddressesByAdrCountryCdvId and AdrStateProvinceCdvId. Here’s the way it should look…

HasRequired(t => t.Country).WithMany(t => t.AddressesByAdrCountryCdvId).HasForeignKey(t => t.AdrCountryCdvId); HasRequired(t => t.State).WithMany(t => t.AddressesByStateProvinceCdvId).HasForeignKey(t => t.AdrStateProvinceCdvId);

Now that’s better! Now not only does my build succeed, but my unit tests all pass as well.

It also may help to use the same technique to View Entity Data Model DDL SQL and see what SQL would be generated to create your tables and constraints.

I hope this helps you find mapping issues in your code first projects. Happy coding.

Best of All

I’m doing a lot of ramping up on Windows 8 these days, and it’s really exciting. I have some experience with HTML, CSS, JavaScript, XAML, C#, and even C++. And with Windows 8, I’ll have the chance to take my pick. Metro-style apps as they’re called on Windows 8 are usually going to be either A) HTML5/CSS3/JavaScript, B) XAML/C#, or C) XAML/C++.

HTML5/CSS3/JavaScript

This route would be a good choice if you already have web development skills and perhaps have an app already developed in these web technologies. I imagine the process will be to grab all of the markup and script from your existing app, paste it into your new Windows 8 app, likely convert the styles to be more “metro”, and then convert the aspects of your app that can use the underlying OS and device features. That’s not nearly as bad as a complete rearchitecture. Even though the languages are compatible, however, the style of a Windows 8 app is rather unique and I don’t know that the application sharing will be quite as cross-platform as some may think.

XAML/C#

This is exciting route in my opinion. I have a ton of web design and development experience, but even HTML5/CSS3 can’t compete with the rich offerings of XAML. And I’ve authored a lot of JavaScript and jQuery, but I would still way rather be in C# writing LINQs and lambdas and interfaces and such.

XAML/C++

And finally, the uber performant, low-level route going with XAML and C++. I don’t personally enjoy writing C++. It’s been too long since college, and for how seldom I need the miniscule performance boost, it’s not worth the productivity hit. I don’t like writing assembly code or machine code either by the way.

So I’m pretty pumped about Windows 8 development. Now get your copy of the developer preview (or the beta before too long!) and start making apps.

Courage is Critical

I was standing on the edge of a cliff overlooking Crescent Lake on Orcas Island with three friends. Just a few moments earlier we were watching other people jump off and into the water far below. It looked fun and we were all excited about it. I can honestly say that I didn’t have the slightest reservation… until I got to the cliff’s edge that is. Sixty feet hadn’t sounded like that great a height a few minutes before, but as I looked over the edge, suddenly it looked so asinine. The survival parts of the brain do their best to talk a person out of things like this, and they were threatening to work on me. I was genuinely scared.

Matt had volunteered to jump first. He was talking big. He was ready to jump - so said Matt, but after a few paces and a few glances over the edge he said, “I’m not ready.” It was very disheartening. His former assuredness was about to convince me that it could be done, and his turn-about was deflating.

Jeremy (not me… another Jeremy) was watching the scene unfold. I don’t know if he was feeling deflated like me, but if he was he didn’t let it interfere with with what he did next - he made a subtle pronouncement, ran to the edge, and shoved off. We watched him hang for some time in the air and hit hard below. We also watching long enough for him to resurface and haloo like an animal. Exhiliration.

What happened in those few seconds was pretty big for me. Jeremy may not have felt courage, but he certainly acted courageously. And whether he meant to or not, he encouraged the rest of us - in the true sense of the word. He didn’t sit us down and fill our ears with a bunch of “you can do it”, “believe in yourself”, and “blah blah blah”. He just jumped.

So I jumped too. It was a long way to the water… long enough to think about the fact that I was still airborn… and then once more. Finally, I hit. It was no big deal really and I let out an involuntary shout after resurfacing too - partly because of the exhiliration and partly because my shin struck the bottom.

Then Matt jumped. And then Scotty jumped too.

That display of courage has been an inspiration to me ever since and my mind has applied it to many a situation - some much like jumping off a cliff and some not at all.

Education, Experience, Inspiration

In my opinion, there are three elements to a balanced and effective professional in whatever field: education, experience, and inspiration. The combination of these elements are essential if a person is going to be a producer - that is - they are going to produce results. I’m a software developer so my mind goes first to the production of software, but the concept is universal.

Think for a bit about a mouse in a maze. You know, the one that learns by trial and error. He runs into decisions and dead ends and each time adds this information to memory to as to eventually rule out all of the ways he should not go. Imagine now that he were able to read an instruction manual or study a map for his maze before he embarks.

The instruction manual is the education and the trial and error is the experience.

Staunch academics will decry the need for experience, claiming that what there is to be known can be read in a book, committed to the brain, and recalled when required. In the other camp, the non-academics - the ones that were all to happy to be finished with school - make opposite claims about the worthlessness of book knowledge. Their claim of “street smarts” is that experience is not only a much better teacher than education, but can almost entirely replace it.

Neither is correct, of course, but the battle will surely rage on.

But I want to talk briefly about a third dynamic - inspiration. Inspiration is the cheese at the end of the maze and perhaps even the intrinsic joy of laying tracks! With education we know how. With experience, we know how not. With inspiration we finally have why.

But it doesn’t always make sense on paper or in our cerebral analysis. We might scan a prospective’s resume like a robot taking in data about schooling and work experience, but we might overlook the passions and objectives. None of the elements in the trifecta should be diminished, but most certainly not inspiration. Without education or experience a person will be behind but without inspiration I submit that he will be lost.

So how do we inspire? The questions on how to impart education and experience have easy answers, but not as much with inspiration. Inspiration is seed tossed into the soil. It requires some receptive soil, some time, and some faith. It’s a tough process. It’s tough because it’s hard to put words to any right method and no one actor is entirely in control.

I’ve always been interested in a concept I call general inspiration. I’ll explain.

I do not play guitar. I wish I did, but I have never loved it quite enough to practice everyday and learn how… which is obviously what is required. But when I hear someone play the guitar I can become rather inspired - not just inspired to play the guitar mind you because I’ve given up on that, but just inspired. I might redirect that inspiration into software or computer graphics or cooking or conversation. But what was given to me via the medium of a the instrument, I give back in another form. Inspiration was, then, the common currency of the transaction.