Nullable Types

Nullable Types

Old forum URL: forums.lhotka.net/forums/t/81.aspx


Brent posted on Friday, May 12, 2006

Hello all.

In reference to the CSLA 2.0:  We currently use a custom datareader that handles nullable types.  Looking at the safedatareader, I couldn't tell how it handles assigning to a nullable type.  Before we go ahead and extend the safedatareader on our own, I was wondering if I missed something.  I searched the old and new forums but didn't find any answer.

Does anybody have any advice or suggestions?

Thanks,

 

Brent

 

tetranz replied on Friday, May 12, 2006

I use nullable types a lot with CSLA 2.

I do this sort of thing with SafeDataReader

_myVar = (DateTime?) dr.GetValue("MyVar");
_myVar = (int?) dr.GetValue("MyVar");

... etc ...

Not perfect I guess but it works just fine. The type of object returned by dr.GetValue can only be the correct column type or null so there is no real danger of the cast failing at runtime.

Ross

Brent replied on Friday, May 12, 2006

Thanks Ross.

That looks good.  The custom reader was doing an internal cast so casting in the object will work just as well.

Brent

Copyright (c) Marimer LLC