clone of the EF code from CodePlex