padgett.com.au Just another WordPress site

27Jun/110

MCPD Certifications

Back in December 2010 I made a concerted effort to complete my MCPD certifications in both Enterprise Application Development and ASP.NET.

So without any further ado:

These certifications are less relevant to my current technical/sales orientated role, but I’m still proud in having achieved them and will most likely upgrade to .Net 4.0 in the near future.

Filed under: Uncategorized No Comments
27Feb/111

Returning a DTO from a one to many relationship

Wrote this neat query the other day.  It queries a 1:M relationship (a make can have zero or more models) and returns a list of tuples, with the third property being a dictionary of makes.  This neatly preserves the make/model relationship and returns the entire hierarchy in one database call.  Thanks to Blair Davidson for the help on this!

  public IEnumerable<System.Tuple<string,int,Dictionary<string, int>>> SelectAllMakeModelsAsReverseDictionary()
        {
            var session = GetCurrentSession();
 
            return session.Query<Model>()
                .Where(x => !x.IsDeleted)
                .Select(x => new
                                 {
                                     MakeId = x.Make.Id,
                                     MakeName = x.Make.Name,
                                     ModelId = x.Id,
                                     ModelName = x.Name
                                 })
                .AsEnumerable()
                .GroupBy(x => new {x.MakeId, x.MakeName})
                .Select(x => Tuple.Create(x.Key.MakeName,x.Key.MakeId,x.Select(y => y).ToDictionary(z => z.ModelName, z => z.ModelId, StringComparer.OrdinalIgnoreCase)));
        }
Tagged as: 1 Comment