Microsoft’s code-first Entity Framework 4.1 nearly done

Microsoft has announced the release candidate of Entity Framework 4.1, the data persistence library for .NET, with a go-live licence. The final release to the web is expected in around one month’s time.

The big new feature is code-first, where you do not need to define a database schema or even a database model. You simply write classes that define objects you want to store, and the framework handles the work of defining the database for you.

Note that according to this article on MSDN:

The Entity Framework is Microsoft’s recommended data access technology for most types of applications.

Of course Microsoft has a long history of data access APIs and keeping up with the latest recommendation over the years has been a challenge. That said, the low-level ADO.NET data API has been in place since the first release of the .NET framework and has evolved rather than been replaced. There has been some confusion over LINQ to SQL versus Entity Framework; but note that LINQ (Language Integrated Query) works with Entity Framework as well.

So what is code-first? A good starting point is VP Scott Guthrie’s post from July last year, where he walks through a complete example using his Nerd Dinner theme. He writes classes to define two entities, Dinner and RSVP. Then he writes the following code:

image

Having defined this NerdDinners class inheriting from DbContext, he can go ahead and write a complete database application.

At this point there is still no database. In the simplest case though, you can just add a database connection to the project with the same name as the DbContext class – in this case, “NerdDinners”. The Entity Framework will use this connection, define a database schema for you, and save and retrieve objects accordingly.

The magic under the hood is an example of convention over configuration. That is, the framework will generate code and schema according to assumptions it makes based on the names used in your classes. For example, it picks up the field named DinnerID and makes it a primary key; and seeing a collection of RSVP objects called RSVPs in the Dinner class, the framework creates a relationship between the two generated tables. You can override the default behaviour with code mapping rules. There is also provision for updating the schema if you need to add or modify the fields, though this is a point of uncertainty in Guthrie’s post.

It looks fantastic; though there are a few caveats. One is that Microsoft tends to assume use of its own database managers, SQL Server or for simple cases, SQL Server CE. That said, there are drivers for other databases; for example devart has code-first drivers for Oracle, MySQL, PostgreSQL and SQLite.

Another point is that there is a trade-off when working at such a high level of abstraction. There is less code for you to write, but a large amount of generated code, which can make debugging or optimizing an application harder. This is a familiar trade-off though; and you could say that hand-rolled SQL is no different in principle from hand-rolled assembly code; you can get fantastic results but the amount of effort and skill required is greater, as is the risk of errors if you get it slightly wrong.

The Mono team has said that it does not intend to implement Entity Framework currently; there is a summary of work needed here. If you want to write .NET code that ports easily to Mono it is best avoided.

Are you using Entity Framework in new .NET projects? I would be interested to hear from .NET developers what approach you take to data persistence.

Microsoft’s stumbling Windows Phone 7 launch – from a fan

Danny Tuppeny’s post on Why I’m Close to Giving Up on Windows Phone 7, as a User and a Developer is worth a read. He describes his experience as a Microsoft-platform developer who is a natural enthusiast for Windows Phone, except that he has been unimpressed with how its launch has been handled.

The first thing he noticed was its lack of visibility on the high street – something I have also observed:

I popped into a Carphone Warehouse over the road from the office where I work on launch day. The staff knew nothing about WP7. I called all the local Orange stores, hoping for a HTC Mozart. Nobody knew when, or if, they would be getting any Windows Phone 7 devices. Wow.

That was not necessarily Microsoft’s fault. It had to convince its operator partners to promote the phone, and they had to convince retailers. All difficult with a launch device, in a market all-but sewn up by Apple and Android between them.

Over to Microsoft then, to convince the world of the value of its device. What would it take? Microsoft needed a start-up mentality. Total commitment to its mobile platform. Regular updates and bug-fixes. Responsive support.

As time went on, cracks started to show. There were bugs. Many bugs. At one point, the SMS message store for my wife got corrupt, which meant I couldn’t send, or read, text messages to/from her. I got in touch with the UK WP7 developer advocate that had sorted out the developer phone for my company, and explained the issue. After many emails going back and forth I was told that there may be logs on my phone that would help Microsoft track down this issue but security procedures do not allow them to share a tool to get the logs off my device. I was instead, told to try a factory reset. This fixed the issue, but Microsoft were no closer to finding/fixing the bug.

So what Tuppeny experienced was the opposite of start-up mentality; rather, the frustration of dealing with a huge corporation.

Next, he was disappointed by delays to the Windows Phone 7 update, promised at launch, that would add copy and paste to the operating system:

The update was delayed. And delayed. There was zero transparency from Microsoft. Despite the rest of the company making huge strides in this area over the previous few years, Windows Phone 7 is a quiet, closed box. Nobody knew what was happening with the update, and more importantly, the bug fixes.

He is not giving up:

I’m not giving up, just yet. I truly believe Windows Phone 7 can be something brilliant, but there are definitely issues that need addressing. To show how seriously I believe Microsoft could make this work, I’ve applied to go and work for the Windows Phone team.

My own perspective on this is that Microsoft as a whole does not convey commitment to its mobile platform. How can this be, when CEO Steve Ballmer makes a point of hyping the phone at events like CES and Mobile World Congress? Well, I ask myself why Microsoft has refused to use the Windows Phone 7 OS in a tablet form factor, for which it seems well suited; and I ask myself how the phone OS can survive if Windows 8 is launched on a multitude of different form factors and device types. Paul Thurrott says it:

I can and have speculated that Sinofsky, as the dominant sub-CEO executive at Microsoft now, will simply swoop in and dismantle WP when Windows 8 is ready, but that is just an uneducated outside opinion, nothing more.

That may well not be the case; but the mere fact that some signs point towards it undermines the platform.

If I were Nokia this would worry me; except that Nokia may also in fact plan to embrace some new Windows 8 thing when the time comes, and one presumes that Microsoft has shared more of its future plans with Nokia’s executives than it has with the rest of us.

What’s the story with IE9 and embedded Internet Explorer?

There is a certain amount of fuss over the fact that Apple’s latest mobile Safari does not give full performance when either embedded in another application, or pinned to the home screen.

It would help if Apple were more forthcoming on the issue; but in general you cannot assume that embedded browser components will behave the same way as the full browser, even when they share common libraries.

I did some quick experimentation with the released Internet Explorer 9 and the .NET Webbrowser control. First, I tried the SunSpider JavaScript benchmark. I had to use version 0.9 since the latest one gives an error in the Webbrowser control. No great surprise: the embedded version was substantially slower. I ran the tests separately, and for the .NET application I ran in release mode outside Visual Studio. IE9 completed in 314.6ms, the Webbrowser control in 578.2ms.

image

While that may seem a bad result for embedded IE, it could be much worse. Unfortunately I did not think to run this test before installing IE9, so I dual-booted into a Windows install that still has IE8 and ran the exact same application. At 6175ms it was more than ten times slower. It was slightly quicker in standalone IE8, but not by much.

image

Next I tried the Fish Tank demo, which tests hardware graphic acceleration.

image

There were two notable facts about my result here. First, the Webbrowser control reports itself as Internet Explorer 7. Second, the frame rate for the two instances was nearly identical. In practice it varied slightly and some of the time the standalone IE9 was fractionally faster, but still close. By way of reference, Apple’s Safari was around 10 times slower.

Update: embedded IE is slower on the Fish Tank than I first realised. 60fps is a kind of maximum for the demo. Embedded IE9 slows to 45fps with 50 fish, whereas full IE9 does not drop below 60fps until 500 fish on my system. It does makes the fans whir though!

My guess is that Microsoft is more concerned about compatibility than performance, when it comes to embedded IE. However, clearly there is significant benefit from IE9 even when embedded.

How can you get embedded IE not to report itself as IE7 and to use full standards mode by default? If it is like IE8, this can only be done on a per-application basis via setting a registry key. That is awkward for developers, who would prefer an API call to set this. I am not sure if there is any change for IE9.

Review: Seagate GoFlex for Mac portable hard drive

I have been trying Seagate’s GoFlex for Mac portable drive, which packs 1TB of storage into a small, light, USB-powered package.

image

The drive measures around 120x88x22mm – small enough to fit easily in a pocket or bag. Spin speed is 5400 RPM which is a little disappointing.

But what makes it a “Mac” drive? Mainly that it comes pre-formatted with Apple’s HFS + (Hierarchical File System Plus) file system, which is ideal for performance and reliability under OS X. A possible snag is that HFS+ is not readable from Windows by default, though Seagate has a solution, of which more in a moment.

It is worth noting that you can easily reformat the drive for Windows NTFS if you want.

There is a GoFlex app for the Mac which includes an information tab, a drive test, and the ability to disable the activity lights on the drive. I cannot imagine why you would want to do that.

image

Seagate’s GoFlex series has a few extra tricks. The most distinctive is that the interface is removable, which means you are not restricted to the usual USB 2.0. This GoFlex for Mac drive come with two, one for USB 2.0 and the other for FireWire 800, which is substantially faster: up to 786Mbps vs 480 Mbps. USB 3.0 and eSATA interfaces are available separately.

Currently the MacBook Pro, iMac, Mac mini and Mac Pro have FireWire 800 ports. It does make sense to use the faster port when available, especially with a drive of this size, though I cannot help thinking it would have been even handier if Seagate had managed to build the two ports into the main case, rather than having them as clip-on extras.

Still, the fact that you can remove the interface enables another GoFlex trick, the ability to slot the drive into a Media Sharing Dock. I’ve reviewed this dock here; it is a handy device though I have some usability concerns. I tried this with the GoFlex Mac and it worked well, an advantage being that you can access the files over a network irrespective of whether your operating system understands HFS+. Trivial point: the GoFlex drive is silver whereas the dock is black, a slight visual mismatch.

But what if you want to direct-attach your GoFlex for Mac drive to a Windows machine? Seagate has done a deal with Paragon to bundle its HFS for Windows driver. This normally costs around $40.00. It works too; though installation was not quite seamless. The problem is that the drive has to be attached for the install to work, presumably to protect Paragon from unauthorised installs. But when you attach the drive, both Windows and the Seagate Manager for Windows (if installed) prompt you to format it.

image

If you agree to format the drive, you will lose any files already on it, so I clicked Cancel. However, while installing the drive software I got this dialog *again* – I suppose the thing to do is to check “don’t show again”. Seagate should update its Windows manager software to be HFS-aware. Once I had the Paragon HFS+ driver installed, and restarted Windows, everything was fine.

I would guess though that most customers for this drive will be using it with Macs and will not run into this issue. It is nice to have a drive designed with the Apple Mac in mind, and with generous 1TB or 1.5TB capacity this is a solid product.

Disclosure: Kudos to Seagate for asking me to mention in my review that that the review sample does not have to be returned.

Poor usability in Microsoft’s Xbox Live billing and support

Leaving aside the defective hardware in its first release, Microsoft’s Xbox console is generally easy to use. I am not so impressed with the way Xbox Live purchases and accounts are handled though.

image

Today’s story begins when I followed a link on the XBox 360 dashboard to upgrade my Live Account to Gold and get a free game: one of Kinect Sports, Kinectimals, Fable 3, or Halo Reach.

I followed the link and tried to pay. I got error 80190848. That’s right, just the number.

Of course I googled it. It seems that it indicates a problem authorising the credit card. Fair enough; the card on file was out of date. But what is wrong with a message that says “We could not authorise your payment; please check your card details”? This is poor usability.

Next, I found I could not delete the old card from my account. To do this you have to go to the Xbox Live website on your PC. However, you cannot take advantage of the special offer from the Xbox Live website. No, you have to use the dashboard, otherwise it does not apply.

OK, I left the dud card there for the moment, added a new card, and made the purchase.

That went through OK, but what about the free game? Nothing. No on-screen information. No message. No email.

OK, so I contacted support. This isn’t too good either. You go to the support page and have to find the tiny contact us link at the bottom of the page. At least that one works. Some paths through the site just don’t work at all. For example, go to My Xbox – Accounts – View Billing History. On the Billing account overview, click Contact support. You get this:

image

Lovely. Note that for Xbox, it says go to to the Xbox Live Accounts and Billing page. Yes, that was where I just came from. I click it anyway:

image

Nice.

Apparently Microsoft has lost a significant amount of money because of weak cryptography in its Xbox Live Points scheme. I wonder how much more it has lost thanks to annoyed or frustrated would-be customers?

Fast JavaScript engine in Apple iOS 4.3 is in standalone Safari only, but why?

Now that Apple iOS 4.3 is generally available for iPhone and iPad, users have noticed something that seems curious. The fast new “Nitro” JavaScript engine only works in the standalone Safari browser, not when a web app is pinned to the home screen, or when a web view is embedded into an app.

This link at mobilexweb.com shows the evidence. Here is the SunSpider test standalone, showing a time of 4098ms, and pinned to the home screen as an app, where it shows 10391.9ms:

image image

The consequence: apps created using WebKit as a runtime, for example using PhoneGap, will not get the benefit of Nitro.

It would be easy to conclude that Apple is deliberately hobbling these apps in order to protect native apps, which can only be installed via Apple’s App Store and are subject to its 30% cut. However that might not be the case. It could be a bug – according to Hacker News it has been reported as such:

To add another note to this, its a bug that Apple seems to know about. I can’t link to it because its marked CONFIDENTIAL across the top of the dev forums, but in short its known about and being investigated.

or it could be a security feature. Using a just-in-time compiler exposes the operating system more than just interpreting the code; perhaps Safari has more protection when running standalone.

Either way, with the increasing interest in WebKit as a de facto cross-platform application runtime for mobile, this particular limitation is unfortunate.

Update: There are also reports of the HTML 5 offline cache not working other than in full Safari:

I’ve tested this by switching apple-mobile-web-app-capable from ‘yes’ to ‘no’ and offline cache works as expected. But whenever it’s switched back to ‘yes’, it’s not working anymore. This occurs when the app is standalone at home screen. As a website, viewed with Safari cache is working as expected.

Guardian.co.uk enthuses about MongoDB, plans to ditch Oracle

The Guardian’s Mat Wall has spoken here at Qcon London about why it is migrating its web site away from Oracle and towards MongoDB.

He also said there are moves towards cloud hosting, I think on Amazon’s hosted infrastructure, and that its own data centre can be used as a backup in case of cloud failure – an idea which makes some sense to me.

So what’s wrong with Oracle? The problem is the tight relationship between updates to the code that runs the site, and the Oracle database schema. Significant code updates tend to require schema updates too, which means pausing content updates while this takes place. Journalists on a major news site hate these pauses.

MongoDB by contrast is not a relational database. Rather, it stores documents in JSON (JavaScript Object Notation) format. This means that documents with new attributes can be added to the database at runtime.

Although this was the main motivation for change, the Guardian discovered other benefits. Developer productivity is significantly better with MongoDB and they are enjoying its API.

Currently both MongoDB and Oracle are in use. The Guardian has written its own API layer to wrap database access and handle the complexity of having two radically different data stores.

I enjoyed this talk, partly thanks to Wall’s clear presentation, and partly because I was glad to hear solid pragmatic reasons for moving to a NoSQL data store.

Microsoft remakes WCF for REST and the web

WCF is Windows Communication Foundation, the part of Microsoft’s .NET framework that handles service-oriented architecture. When WCF was first designed Microsoft was betting on SOAP web services. SOAP is still widely used but since then the trend has been towards more web-friendly services based on REST (Representational State Transfer) and JSON (JavaScript Object Notation). Microsoft has always argued that WCF is flexible enough to support such alternatives.

That said, a project which I have become aware of here at QCon London is the WCF Web APIs, presented here by Microsoft’s Glenn Block. WCF Web APIs focus on support for REST, JQuery clients, and programming model simplicity for a variety of other clients such as Silverlight and Windows Phone. The bit that surprised me is that WCF Web APIs are not just another wrapper for WCF; it is a completely new library that does not build on the old WCF Service Model. The fact that it is called WCF at all is confusing, though of course it belongs in that space within the overall .NET Framework.

I have not had time to look in detail at the WCF Web APIs, but from what I have seen and heard they are well worth exploring, even if you have found the old WCF somewhat impenetrable.

Windows 7 Service Pack 1 install failures common?

There are reports coming in of Windows 7 install failures causing problems for users. There will always be some failures, but normally there is an easy way to rollback; unfortunately SP1 is making machines unbootable in a number of cases:

I have about 10pc’s in my company. They all failed this morning after the service pack 1 for windows 7 x64 systems.

I wonder on a global scale what financial damage this service pack caused. Isn’t a service pack made for fixing issues instead of creating new ones.

So now what? Tomorrow windows installs it again and the company stops working again? Is there a fixed update in the making???

A typical issue is “fatal error c0000034 applying update operation”.

If this happens to you, there are some emergency fixes suggested in the thread referenced above.

Google on innovation – or should that be copying?

Patrick Copeland, Google Director of Engineering, gave the keynote at QCon London this morning. His theme was innovation: how it works at Google and elsewhere.

I was expecting some background on Google’s famous 20% time, where employees spent up to one day a week on something not in their job description, but I don’t think Copeland even mentioned it. In fact, he almost argued against it. There is no shortage of bright ideas, he said, and Google has over 100,000 of them in a database; but what matters is not idea, but innovators who have the ability to take a good idea and make it into a product.

He added that whatever “it” may be, building the right “it” is more important than building “it” right. If what you build is the wrong thing, it will not succeed, whereas the right idea will sometimes succeed despite poor implementation. Twitter and its well-known fail whale comes to mind.

Google’s record on innovation is mixed. You can make a long list of Google projects that have failed, from Lively – a kind of Second Life clone – to Google Wave. “You want to fast fail when things aren’t working” said Copeland, making the best of it.

On the other hand, Copeland mentioned GMail as a positive example. I would quibble a bit with this: was GMail innovation, or simply Hotmail done right?

Copeland also mentioned two other examples. The Chrome browser, he said, had two goals: to streamline the user interface so less screen space was wasted, and to have a fast JavaScript engine to show off Google apps. He also observed that rival browsers have copied both ideas; and it is true that Microsoft’s Internet Explorer 9, which will be released on March 14, happens to have both these features.

What about Android? Copeland said that the Android strategy vs Apple is similar to that of the clone PCs vs IBM in the eighties. He tried to make a point of innovation here, observing that IBM could not compete with innovation from many independent vendors, but this seems to me a stretch. The point about the clone PCs was that they were kind-of the same as the IBM PC but cheaper and faster. It was more about copying than about innovating. I think you can see this playing out with Apple vs Android to some extent, in that there are customers who will end up with an Android smartphone or tablet because it is kind-of the same as an iPhone or iPad but cheaper or with better specifications.

On the other hand, Apple is doing a better job at differentiation than IBM achieved with its PC; and technically iPhone apps do not run on Android so the parallel is far from exact. Many of the same apps are available for both iPhone and Android, so from user’s perspective there is some similarity.

The quick summary then: most innovations fail, and you need innovators rather than simply bright idea. The implication is that successful innovation happens when you have a company with lots of money to spend on projects that will likely fail, and that has a culture which attracts innovators. Google ticks both boxes.

Incidentally, when I asked how Google identifies its innovators Copeland said that you do not need to. They make a nuisance of themselves, so if you have them, you know.