Thursday, May 21, 2009

Improvement to return a single row from stored procedure

Ok, the method I posted previously wasn't good enough. There is no handling for null result. Updated method:

public static ThisTable GetUser(int uid)
{
        DataClasses1DataContext dataContext = new DataClasses1DataContext();

        ThisTable myTable = new ThisTable();
        ISingleResult result = dataContext.GetUser(uid);

        var details = result.ToList();
        if (details.Count > 0)
        {
                myTable = details[0];
        }
        return myTable;
 }

No comments: