Page 1 of 1

Custom DataType Mapping ...

Posted: Tue 14 Apr 2009 13:56
by DeepDiver
Hi,

I'm currently evaluating dotConnect for Oracle and I have one question:

Is it possible to perform custom data type mapping?

Allow me to give you an example:
There is a column defined as char(1) NOT NULL, which will hold Y or N.
In the Entity Developer this is mapped to System.String.
I want to change the type - well lets call it class YesNo.
To get the correct value written to the database I just override ToString() and return Y or N.
But on reading the data from the database I get an InvalidcastException.
implicit and/or explicit conversion operators from string don't help.

Any idea?

THX alot,

Tom

PS: Allow me to congratulate you for this cool product! ;-)

Posted: Wed 15 Apr 2009 08:49
by AndreyR
The simplest way for handling the situation is to implement a new public wrapper property in your class.
Here is an example using the bool wrapper:

Code: Select all

public partial class myEntity {
  public bool MyWrapperProperty{
    get{
      //Here is to be the code converting the myColumn value to bool
    }
    set{
     //Here is to be the code converting the bool value to myColumn
    } 
  }
}
Of course, you can implement wrapper property of any other type.