views:

195

answers:

1

I wish to return a single ScPollOption item using a Stored Procedure via the code below:

public ScPollOption FetchPollOptionByID(int optionID)
    {
        StoredProcedure sp = SPs.ScPollOptionGetOptionByID(optionID);
        return sp;
    }

When working with a query I would use:

ExecuteSingle<ScPollOption>()

but SubSonic only allows for sp.ExecuteTypedList<> and sp.ExecuteScalar<>.

How can I return a single ScPollOption item?

Thanks

Dan

+2  A: 

I know it's not terribly attractive, but this would work if you're able to use the LINQ extensions:

sp.ExecuteTypedList<ScPollOption>().FirstOrDefault();

You could also execute an IDataReader and inflate the ScPollOption object manually:

ScPollOption item;

using (IDataReader reader = sp.ExecuteReader())
{
    if (reader.Read())
    {
        item = new ScPollOption();
        item.SomeProperty = reader.GetValue(0);
        // Set additional properties
    }
}

return item;
Marve
Many thanks Marve this worked great!
McDotNet