This is a migrated thread and some comments may be shown as answers.

Map Varchar(1) to Bool

6 Answers 123 Views
Databases and Data Types
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Alex
Top achievements
Rank 1
Alex asked on 20 Sep 2010, 05:58 PM
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.

6 Answers, 1 is accepted

Sort by
0
Ady
Telerik team
answered on 23 Sep 2010, 02:05 PM
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
0
Alex
Top achievements
Rank 1
answered on 23 Sep 2010, 06:50 PM
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.
0
Alex
Top achievements
Rank 1
answered on 24 Sep 2010, 07:39 PM
Hello, 

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

Sds,
0
Ady
Telerik team
answered on 28 Sep 2010, 11:04 AM
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
0
DuelingCats
Top achievements
Rank 2
answered on 19 Feb 2013, 05:39 PM
Is it still the case that there isn't an automatic way to make a varchar 1 to bool?
0
Ady
Telerik team
answered on 22 Feb 2013, 06:02 PM
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.
Tags
Databases and Data Types
Asked by
Alex
Top achievements
Rank 1
Answers by
Ady
Telerik team
Alex
Top achievements
Rank 1
DuelingCats
Top achievements
Rank 2
Share this question
or