Flattening nested object properties in Entity Framework & ASP.NET MVC

When using the Microsoft ASP.NET MVC framework, I always create a set of partial classes relating to my database objects to centralise validation and add additional properties. When using Telerik Grid control for MVC, however, you cannot bind, page or sort when there is a column which is bound to such a property because Entity Framework fails to translate those properties to SQL.

Occasionally, you just need to create a flattened representation of a set of objects and one solution is to use LINQ "projection" to output a flat view model object:

Here’s the ActionResult which, using projection, flattens the UserModel enumerables into a flat UserViewModel:

 [GridAction]        public ActionResult _UserGrid()        {            var model = from o in new UserRepository().GetUsers()                        select new UserViewModel                        {                            Full_Name = o.Person.Person_nameFirst,                            Created = o.Created,                            Email = o.Person.First,                            ID = o.ID,                            Username = o.Username                        };            return View(new GridModel { Data = model });        }

Here’s the view model itself:

namespace Project.EF{    public class UserListViewModel    {        public int ID        {            get;            set;        }        public string Full_Name        {            get;            set;        }        public string Username        {            get;            set;        }        public string Email        {            get;            set;        }        public DateTime? Created        {            get;            set;        }    }}

And here’s our original partial class

namespace Project.EF{    [Bind(Include = "myfields")]    [MetadataType(typeof(User_Validation))]    public partial class User    {        public string FullName        {            get { return string.Format("{0} {1}", Person.First, Person.Last); }        }        public bool IsValid        {            get { return (GetRuleViolations().Count() == 0); }        }        public bool IsValidRecord        {            get { return (ID > 0); }        }        public IEnumerable GetRuleViolations()        {            yield break;        }    }    public class User_Validation    {        [HiddenInput(DisplayValue = false)]        public int ID { get; set; }    }}

Get it together, RIM!

I posted my opinion on the BlackBerry PlayBook tablet a few weeks ago and maintain that it is a solid piece of engineering. It’s slick, fast, intuitive and has so much potential. I wonder, however, whether it’s already too late to recover the device from what so many consider an extremely shaky start.  I, for one, hope it isn’t.

I have been following the progress of the PlayBook since its inception and have read through many user comments (some positive, mostly negative) on popular tech sites like CrackBerry and Engadget. Most of the negative feedback derives from the lack of an e-mail client and the questionable quality of the applications available on App World. Others are from users who feel the company have placed too much emphasis on the new tablet and not enough in bringing their ageing line of smartphones up to date.

Since the PlayBook launch, some users have been extremely vocal about their frustrations and many believe that RIM’s popularity, like their share price, is on a downward spiral. Others, possibly for nostalgic reasons or just because they make great products, are quick to defend the company and its products.

The bottom line is, the company needs to do something to make people want its products again, and when it comes to the PlayBook, I think they have gone a bit awry in forging and maintaining developer relationships.

I believe that the key to the success of this device lies in developer adoption. Although Apple and Google have been at the game longer, the tablet market is well established and a lot can be learned from previous mistakes. Many criticised Apple for being too stringent with requirements, however RIM seems to have gone in the opposite direction.

The free PlayBook offer which ran between January and March this year seems to have populated App World with what can only be described as a casserole of nonsense. Instead of issuing what must have been thousands of free devices, why not pay a couple of the major players to develop apps for your platform. I do not want a poorly titled farting application to be the first app that appears in App World when I show my iPad owning friends and collages (ready to pounce with criticism) the device and I’m sure the majority of users of this “business tablet” would agree.

Additionally, months after the US launch, RIM seems to be allowing their own rules to be violated, leading to an inconstant user experience across App World. Here’s a screenshot with 4 items potentially damaging the integrity of the service.

  1. How on earth did an app get approved with the user’s _Signed extension?
  2. The capitalisation of the hangman app just makes it look untidy.
  3. “Edges not rounded off” is a requirement of the spotlight image. This looks awful.
  4. “Positive user reviews and application rating (3+ star rating)”. Two stars?

Users also can’t see the top apps in each category and are instead presented with category names and a list of apps. Adding some structure to the App World would go a long way in bringing the better apps to the forefront and hiding the junk. This would also encourage developers to add more finesse to apps to ensure their sales were up. Right now, the only real way to get sales volume is to get featured.

The scope of RIM’s product portfolio is astonishing. BlackBerry smartphones cater to such a wide audience; from the 12-year old BBM addicted teenager to large corporate customers requiring high levels of encryption and compression. Despite a bad quarter, I’m sure the company will continue to innovate in both the consumer and business spaces in the future and its growth will accelerate again in 2012 as QNX, their new operating system, is ported over to BlackBerry phones. This will mark a new era for the company.

I just really hope they can get the PlayBook up to speed and get developers on board as quickly as possible in order to kick start this era early!

Scotranslate for BlackBerry PlayBook

Since the BlackBerry PlayBook due to launch in the UK on June 16, I thought I’d write an app for Scotranslate.

The app is now on sale in BlackBerry App World for $0.99/£0.99 and will initially give users the ability to search for English to Scottish translations from their BlackBerry PlayBook device.

Scotranslate is a user contributed community translation project allowing visitors to search for Scottish versions of words or phrases.  If a word or phrase isn’t recognised by Scotranslate, it is submitted for user translation, and once a registered user clicks ‘Start Translating’, they will be presented with words and phrases at random, one at a time.

If the user sees a previous translation for this word/phrase that they agree with, they vote for it, otherwise, they enter their own interpretation and press suggest.  If a word or phrase gets 5 votes, it will appear in the Scotranslate dictionary. If it’s voted bad 5 times, it will be removed forever!
Here are a few screenshots:

PlayBook 1

PlayBook 2