Pages

Saturday, June 15, 2013

Creating JavaScript List Repositories for the SharePoint REST API

I've recently been working on a project where I've been leveraging the SharePoint 2010 REST API. It is a great experience especially after moving from SharePoint 2007 client side development. I've been able to develop web parts that are 100% client driven with no reliance on any server side code other than the REST services that SharePoint already exposes.

As I began developing I quickly noticed that calls to jQuery ajax and getJSON functions were littering my code. Of course, these calls are completely necessary, but I wanted to find a way to reduce duplication, increase reuse, and create a better programming experience for the rest of the effort. I decided to take these calls and create a wrapper object that would be responsible for the plumbing of calling my lists. What I ended up with was an object very similar to a traditional repository used in other languages.

Thursday, March 7, 2013

Validating your data and your feelings with IE 10 and HTML 5

On a recent project I ran into an unexpected issue while testing with IE 10. The site that I was working on has out of the box ASP.Net validators and custom ASP.Net validators. When I navigated to the page that contains the validators and attempted to submit the form, multiple validators fired.


Thursday, June 28, 2012

No ELMAH, forget about it!

If you haven't heard of ELMAH you need to check out the following links pronto!

ELMAH - Home
Scott Hanselman on ELMAH

I highly recommend using ELMAH whenever you can when developing custom applications. There are very few things that you can "bolt-on" to your application that will provide so much functionality with so little effort.

But what happens when you can't use ELMAH? If for some reason you can't use ELMAH in your application (like, for say... you work with an old school architect who just doesn't get it, and doesn't want to try to get it) then what do you do? What you do is forget about it, and write your own!

Wednesday, June 27, 2012

Using Pete Montgomery’s Universal Predicate Builder with a generic repository

I gave a presentation the other day that included a generic repository class that I created and use in many of my Entity Framework projects. I like the implementation because it is flexible and easy to extend. I've created a blog post about the RepositoryBase class here:

A Generic Repository for the Entity Framework

After the presentation I was asked how I utilized the repository's Select methods. In this case, the Select Method is overridden a few times to match the select pattern used by ASP.Net ObjectDataSources. Essentially, I can create a repository class that will map 1 to 1 to an ObjectDataSource to enable paging and sorting.

Wednesday, June 13, 2012

A Generic Repository for the Entity Framework

Note: In this post I am going to be demonstrating techniques that depend on the Entity Framework 4.1 or higher.

Recently I’ve been using a simple Repository oriented architecture for my Entity Framework projects. Coupled with the new DbContext class and the entity code generation items added in the Entity Framework 4.1 release you can quickly scaffold up a data layer and business layer for your application.

To start, let’s define an interface for our repository:

public interface IRepository : IDisposable
{
    void Insert<E>(E entity) where E : class;

    void Update<E>(E entity) where E : class;

    void Delete<E>(E entity) where E : class;

    IQueryable<E> Select<E>() where E : class;

    E Select<E>(object key) where E : class;

    int SaveChanges();

    int SaveChanges(bool validateEntities);
}