tags:

views:

148

answers:

2

I tried to search for it on google but couldn't find the answer so i'll try it here. I am using Subonic and am trying to fill an object by using:

Model.Object o = new Select()
            .From<Object>()
            .Where("Id")
            .IsEqualTo(id)
            .ExecuteSingle<Model.Object>();

When doing so i get the error: Object of type 'System.String' cannot be converted to type 'CustomType' One of the properties is stored in the database as varchar. In the Model.object this property is defined as CustomType. I already added an implicit operator to this type as folows:

public static implicit operator CustomType(String value)
    {
        return new CustomType(value);
    }

What am i doing wrong here? or am I missing something? any help is appreciated

A: 

Try implementing your own TypeConverter so that it will be possible to recreate your Model.Object from string representation.

EDIT. After digging through SubSonic code I found out that this won't help (see this, BuildTypedResult<T>). Try implementing IBaseRecord if you like to, and implement Load() method.

Anton Gogolev
I tried but with no succes. breakpoints in the converter class are not hit. i am clueless
Anton Maters
Then i would be better of useing the generated class from SubSonic.
Anton Maters
A: 

If this were my project, I would probably build out a partial class for Model.Object, and then pop a factory method on there or maybe another constructor overload that takes a Reader. You can then use that reader to load the properties as needed, casting your CustomType.

Rob Conery