Search code examples
databasec#-3.0subsonicidatareader

In Subsonic 2.1 how do I get a strongly typed object from find?


In Subsonic 2.1 how do I get type T from Find?

        Animal criteria = new Animal();
        IDataReader result = Animal.Find(criteria);

I want result to be of type Animal not IDataReader. How can I convert IDataReader to Animal? I hope there is a SubSonic or Framework method to do this for me.


Solution

  • Try this (from the Getting Started PDF Documentation):

    IDataReader result = Animal.Find(criteria);
    AnimalCollection coll = new AnimalCollection();
    coll.Load(result);
    result.Close();
    
    // do something with coll
    foreach (Animal anm in coll)
    {
        // do something with animal object
    }