Packt offers buy one, get one free book offer

Packt Publishing has published their 2000th book!  You can buy my book RavenDB: High Performance and many more from Packt in this amazing Buy One, Get One Free offer  http://bit.ly/1j26nPN

 

Playing Spotify (and other audio) via AirPlay

Two of my favorite things working together: Spotify & AirPlay.  This tip lets you play your Spotify library for free on your home theatre! 

If you have a Mac, simply hold down the option key when you click on the audio menu option.  You can then send just the audio to an Apple TV or AirPort.  If you're on Windows, you'll need to use something like Airfoil for Windows.

Take a look at this article from Cult of Mac for other cool uses for the option key.

Posted by brian_ritchie | with no comments
Filed under: , ,

Reviews: RavenDB High Performance

My book RavenDB High Performance was recently published by Packt Publishing. The team at Packt was great to work with and I had support from a strong group of reviewers: Ayende Rahien (of RavenDB fame), Paul Stovell (founder of Octopus Deploy), and Mohammed Ibrahim.

I really enjoyed writing the book and hope that readers enjoy reading it! The goal of the book was to dig into the advanced topics that would help developers take their applications to the next level.  Once you get the basics down, this book will help you optimize your applications for higher levels of scalability and functionality.

Need more encouragement to get a copy?  :)

Ayende Rahien
"To summarize, go ahead and do the cool stuff first. But pay attention to the whole book. I think that Brian has done an excellent job in getting the crucial information you need to really get the most from RavenDB. And this book is one of the best ways to go from being merely proficient to being absolutely awesome." [ From the book's forward ]

Brian Federici
"In some ways, I found the book easier to follow than the online RavenDB documentation. While it's not extensive enough to replace the online docs, I found the organization of the book to be more logical and it did a better job of surfacing the core knowledge you'd need day-to-day." [ Full Review ]

Sebastian Gebski
"The best book on RavenDB that is available currently (but not for absolute beginners!) This book is a clear win - it's a short but very practical guide to the most crucial aspects of RavenDB. To summarize: if you're considering RavenDB for your product / service, give this book a go, it will help you to understand what's Raven capable of." [ Full Review ]

Johnny Graber
"There are many tricks to squeeze more performance out of the API. Most of them are not part of the official documentation and when only as a comment to a more general topic. Brian made a big effort to collect them. And luckily for us he can explain them in a beginner-friendly way as well." [ Full Review ]

I really appreciate the kind words of these reviewers.  This is my first book and I tried to pour into it the things that I would want to learn if I were buying a book on RavenDB.  Please check it out and let me know what you think.

Posted by brian_ritchie | with no comments
Filed under: , ,

Moving from an entity model to a RavenDB document model

I have an application that I'm moving from a SQL Server database to a RavenDB Document Database. The first order of business is updating the data model. Document data modeling and relational data modeling are totally different.

Below is part of the data model.  It contains the relationship between Camps & Programs.  For this application, a camp can have multiple programs.  A program is a specific type of activity program for a given age or grade.  For example, a sports summer camp may have a baseball program for 2nd to 4th grade.  In a relational database this concept is actually fairly complex to model.

Entity Relationship Model

While the relational database model is fairly complex and will require lots of joins to access, the corresponding document data model is nice and simple. 

Document Data Model

There are two documents.  The Camp document contains a collections of references to the related Program document.  While you could model this as one big document, the application allows users to search at the Program level & schedules Campers at the program level. This is why the Program document is separate.

The JSON for a Camp looks like the following: 

camps/ce87d45b-87dc-4d23-a67e-06de97235d8b
{
  "Name": "High School Sports Camp",
  "Contacts": [
    {
      "Type": "Staff",
      "Name": "Kathleen Smith",
      "EmailAdress": "katsmith9919@gmail.com"
    }
  ],
  "Programs": [
    {
      "Id": "programs/75df8120-5f98-479f-bb2c-b0748b6c063d",
      "Name": "Baseball Camp - Session 1"
    },
    {
      "Id": "programs/762ee139-5470-4eb6-9142-501e217c26f0",
      "Name": "Baseball Camp - Session 2"
    }
  ]
}

And the JSON for a related Program

programs/762ee139-5470-4eb6-9142-501e217c26f0
{
  "CampId": "camps/ce87d45b-87dc-4d23-a67e-06de97235d8b",
  "CampName": "High School Sports Camp",
  "Category": "Sports",
  "Name": "Baseball Camp - Session 2",
  "Ages": [],
  "Grades": [
    9,
    10,
    11,
    12
  ]
}

The nice thing about document models is you can also denormalize data to improve access.  In this example, I've included the Camp Name in the Program Document and the Program Name in the Camp document.  This saves additional document loads to get basic information.

Hopefully this gives you some insight into document data modeling. It is key to building an efficient, easy to develop applications. 

My new book, RavenDB High Performance, covers this topic in depth and much more.  I encourage you to check it out if you are building document databases.

 

Posted by brian_ritchie | with no comments

A technique for computed columns in LINQ-based EF queries

Have you seen this message before? 

LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.

It is one of my favorite LINQ to EF messages! LINQ is pretty smart at translating C# expressions into SQL.  But, there are lots of simple things that can blow its mind.  Here is an example:

                var camps = from c in db.Camps
                            select new {
                                CampId = "camps/"+c.CampId                             
                            };

This error will occur if CampId is a Guid.  It can also occur if you are trying to call a function or perform some sort of complex manipulation.

A easy way to solve this problem is to put the results of the query into a class with computed properties.  It might be tempting to put this logic into a constructor. However, LINQ to EF only supports parameterless constructors so this would be a no-go.

Here is an example:

   public class Camp
    {
        public string CampId { get; set; }
        public Guid CampGuid
        {
            set
            {
                CampId = "camps/" + value;
            }
        }
   }

   var camps = from c in db.Camps
                        select new Camp {
                                CampGuid = c.CampId 
                         };

The nice thing about this approach is the CampGuid property won't be serialized to JSON since it only has a setter.

Alternatively, you could have the getter do the calculation: 

   public class Camp
    {
        public string CampId 
        {
            get
            {
                return "camps/" + CampGuid;
            }
        }

        public Guid CampGuid { get; set; }
   }

 

This even works with more complex examples.  In this case, I have a model that is being serialized to JSON.  The JavaScript is expecting the dates in Unix format, while EF returns the dates in a C# DateTime class.  The same technique can solve this problem as well:

    public class CalendarEventModel
    {
        private long ToUnixTimespan(DateTime date)
        {
            TimeSpan tspan = date.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0));
            return (long)Math.Truncate(tspan.TotalSeconds);
        }

        public DateTime startDT { get; set; }
        public DateTime endDT { get; set; }
        public long start { get { return ToUnixTimespan(startDT); } }
        public long end { get { return ToUnixTimespan(endDT); } }
   } 

 

   var q = from schedule in db.CamperSchedules
                select new CalendarEventModel()
        {
              startDT = schedule.StartDateTime,
              endDT = schedule.EndDateTime
        };

Posted by brian_ritchie | with no comments
Filed under: , ,

Creating your development home page using GitHub Pages

It was time to update my developer home page.  In the past, I've been focused on using server-side technology to create the page.  However, times have changes & the server-side isn't all that important for this site. It was more important to have something that was easy to maintain & super-low cost.

Enter GitHub Pages. It gives you versioning, automated publishing, custom domain names, and it is free!

Here is my new site using responsive (and mobile friendly) HTML5 site beside my old and busted site.

 

To setup the site with GitHub:

  1. Create a new repository.  I called mine "pages". 
  2. If you want to use a built-in template, click Settings->Automatic Page Generator
    see https://help.github.com/articles/creating-pages-with-the-automatic-generator
  3. If you want to upload your own HTML, create a branch called gh-pages, clone the branch and commit your files
    see https://help.github.com/articles/creating-project-pages-manually

Now your site is available at http://username.github.io/projectname. In my case, http://dotnetpowered.github.io/pages.

If you want to point your own domain, create a CNAME file in the root folder containing your domain name.  Next, point your DNS A record at 204.232.175.78. See https://help.github.com/articles/setting-up-a-custom-domain-with-pages

 

Learn more about this functionality at http://pages.github.com. See my repository for an example.

CQRS at Jax Code Camp 2012

Continuing my CQRS world tour...I gave my CQRS presentation at the Jax Code Camp 2012 this past Saturday.  It was a great crowd with lots of representation from the wicked smart engineers at Feature[23] and others from the Jacksonville developer community.

If you'd like to take a look at my slide deck, they are out on SlideShare. The code I demoed is from Ashic Mahtab and is posted on github.  

If you can't get enough of CQRS, Microsoft has joined the CQRS party with their CQRS Journey which includes a free e-book called Exploring CQRS and Event Sourcing.

Posted by brian_ritchie | with no comments
Filed under: , ,

Hosting Windows Services in IIS Presentation at JAXDUG

Thanks to everyone who came out for my presentation at the Jacksonville Developer User Group tonight. 

 


Migrating from ASPX MVC views to Razor

 Razor-based view templates are a much cleaner way to construct MVC views in ASP.NET.  However, they were only released fairly recently with MVC3.

 If you still have some ASPX-based templates that you'd like to upgrade, Telerik has released a free tool to do just that.

Posted by brian_ritchie | with no comments
Filed under: , ,
More Posts Next page »