Projection to custom classes and type conversions

Posts   
 
    
mosachri
User
Posts: 3
Joined: 27-Jul-2006
# Posted on: 08-Aug-2006 16:10:23   

Hello,

I have to write an EntityView2 projection onto a custom class which I can't modify. There is a type conversion problem as my Entity has a decimal field that I want to put into an Int32 property of my custom class.

The CreateProjection method of my EntityView2 class throws an "Object of type 'System.Decimal' cannot be converted to type 'System.Int32'." exception.

Has anybody an idea on how to proceed ?

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 08-Aug-2006 19:05:21   

hi,

There is a virtual "ValuePostProcess" method in the EntityProjector which you should be able to override in a custom implmentation.

Make the conversion in your own inherited property projector and it should be ok.

mosachri
User
Posts: 3
Joined: 27-Jul-2006
# Posted on: 09-Aug-2006 10:22:50   

Thanks for reply.

I've found yesterday another thing which works fine: Adding a new read-only property to my entity in the custom code area, which returns the value in the type that I want. Then in the projection I use the EntityProperty("") thing.

Any idea about which solution is better (in terms of perfomance and design) ? Overriding the EntityProjector and implementing ValuePostProcess or adding a new property in the entity ?

Thanks.

Christophe.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 09-Aug-2006 11:09:53   

WOn't make much difference. The EntityProperty has a small startup delay as it has to reflect over the type and has to grab the propertydescriptor for the particular property. However this delay is really minor. It caches the propertydescriptor so it won't get this small delay with every row.

Frans Bouma | Lead developer LLBLGen Pro