Put logic behind generated LinqToSql fields

Posted by boris callens on Stack Overflow See other posts from Stack Overflow or by boris callens
Published on 2009-02-13T16:28:46Z Indexed on 2010/05/16 22:40 UTC
Read the original article Hit count: 265

Filed under:
|

In a database I use throughout several projects, there is a field that should actually be a boolean but is for reasons nobody can explain to me a field duplicated over two tables where one time it is a char ('Y'/'N') and one time an int (1/0). When I generate a datacontext with LinqToSql the fields off course gets these datatypes.
It would be nice if I don't have to drag this stupid choice of datatype throughout the rest of my application. Is there a way to give the generated classes a little bit of logic that just return me

return this.equals('Y');
and
return this==1;

Preferably without having to make an EXTRA field in my partial class.
It would be a solution to give the generated field a totally different name that can only be accessed through the partial class and then generate the extra field with the original name with my custom logic in the partial class. I don't know how to alter the accesibility level in my generated class though..

Any suggestions?

© Stack Overflow or respective owner

Related posts about c#

Related posts about linq-to-sql