Map Varchar(1) to Bool

7 posts, 0 answers
  1. Alex
    Alex avatar
    5 posts
    Member since:
    Sep 2010

    Posted 20 Sep 2010 Link to this post

    Hello, 

    I would like to know if it is possible to map Varchar(1) to boolean. I am using Oracle as Database, and boolean is stored as Varchar(1) = 'S' to True and 'N' to False.
  2. Ady
    Admin
    Ady avatar
    589 posts

    Posted 23 Sep 2010 Link to this post

    Hi Alex,
     
     We are currently working on a mechanism where this would be possible and you can 'plug in' your own implementation that decides what is a 'true' value and what is 'false'.

    At the moment what you could do is map the column to a 'char' member field in your class and implement the IInstanceCallbacks interface to check this value and assign the appropriate value to another 'bool' transient field.  This way the 'char' fields get persisted to the database and you get/set the value via the 'bool' which is transient (not saved to the database).

    Do get back in case you have further questions.

    Greetings,
    Ady
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Alex
    Alex avatar
    5 posts
    Member since:
    Sep 2010

    Posted 23 Sep 2010 Link to this post

    Hello Ady, 

    Thank you by the solution, I dealed with this in a different way, changing the string property privacy to "Private" and creating another public property in the partial class that maps 'S' and 'N' to Boolean. I really would like to know about a native way to implement, I hope it can be released soon.

    Thanks.
  5. Alex
    Alex avatar
    5 posts
    Member since:
    Sep 2010

    Posted 24 Sep 2010 Link to this post

    Hello, 

    Addy I was testing your solution and implementing IInstanceCallbacks.
    But how can I configure the generated class to implement the Interface IInstanceCallbacks ? 

    Sds,
  6. Ady
    Admin
    Ady avatar
    589 posts

    Posted 28 Sep 2010 Link to this post

    Hello Alex,

    Currently there is no tool/wizard to automatically implement this interface for you. All you need to do is implement methods of this interface in your class (as shown in the help) and the OpenAccess runtime will invoke the appropriate methods when the events occur.

    Do get back in case you need answers to specific questions on how to implement the interface.

    Best wishes,
    Ady
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. DuelingCats
    DuelingCats avatar
    49 posts
    Member since:
    Jul 2012

    Posted 19 Feb 2013 Link to this post

    Is it still the case that there isn't an automatic way to make a varchar 1 to bool?
  8. Ady
    Admin
    Ady avatar
    589 posts

    Posted 22 Feb 2013 Link to this post

    Hello Alex,

     I have prepared a sample for you where you can convert between a varchar(1) to a Bool. Following is some information related to that
    1. When you reverse map your schema to a model you need to explicitly specify the CLR type as 'bool'. By default a varchar(1) will be mapped to a 'char'
    2. Converting between a character to a boolean is done via the 'Type converter' framework. I have implemented a custom type converter - VarcharToBooleanConverter which does this. You can modify it based on your interpretation of 'true' and 'false'
    3. You will also need to create a partial class for your context and override the 'OnDatabaseOpen' method. Here you need to set the converter for the fields that need to be converted.

     Please have a look at the example and get back in case you need further assistance.


    Regards,
    Ady
    the Telerik team
    Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
Back to Top
DevCraft banner