6
Sep

Seamless support for Boolean and GUID datatypes in Firebird and Entity Framework

It may came as a shock but Firebird does not have direct support for neither bools nor guids. On the other hand people around Firebird are smart and came with more or less standard solutions for both. The bool is easy, just use number with constraint to 0 or 1. For guid we (ab)use special character set available in engine. It’s called OCTETS and it’s exactly what you think it is. Just a bunch of binary data, without any other interpretation from engine. That means CHAR(16) and the above character set is a perfect match for storing (not only) guids.

On the other side, where .NET Framework and Entity Framework lives, the bool and guid datatypes are core part of both frameworks. This created a small mismatch or better to say inconvenience. It wasn’t showstopper but working with (or actually without) it wasn’t pleasure either.

But this is over, since today, I used similar trick we used for “identity” columns and added two new special keyword (if I can call it like that). #BOOL# and #GUID#. When you use these (we’re looking for these in whole comment, so you can place it anywhere you want), your model will contain properties with accordant types. (Note, we’re not doing any checks whether your underlying datatype is compatible, it’s up to you.) Similarly the internals of Entity Framework support were improved to handle these changes correctly (as well as Model First support).

If you wanna try it, grab it from SVN or weekly builds and enjoy. And report any problems you encounter, of course.

There's 9 Comments So Far

  • Craig Stuntz
    September 6th, 2010 at 16:32

    The column comment trick seems kind of kludgy. If you don’t do it already, you might want to consider looking at the name of the DOMAIN associated with the column.

  • cincura.net
    September 6th, 2010 at 16:45

    This was considered too. But later, in list IIRC, we decided to use comments.

    The problem with domain is, that it can be whatever you want. With English, I would call it considerable, but for systems using non-English names for tables, columns, domains, views, … Not frictionless. And I’ve seen couple of these (even with national characters :\).

    The code just looks whether the comment contains some special keyword and if so it does it’s job accordingly.

  • Christian
    March 21st, 2011 at 06:53

    Hi! I’m trying to use #BOOL# in my project to use booleans in my entity in c# vs2008, but when I create the entities in the diagram is always is a short. How can I fix this. Please, i need help.

    Thanks for all!

  • cincura.net
    March 21st, 2011 at 08:02

    How did you add the comment? Can you see it in isql or similar tool?

  • Christian
    March 21st, 2011 at 18:31

    Hi!! Thanks for answer.

    I’m using SQL Manager for InterBase & Firebird trial version. There is a Description field for each attribute in the table. Is there where I need to put de comment??

    Otherwise, how I do the bool column? Actually I using a smallint with a check constraint.

    Thanks!!

    P.D. Sorry, my english isn’t good enough.

  • cincura.net
    March 21st, 2011 at 21:23

    Umm, hard to say. I would check with isql that the comment is there and check you’re using right version of .NET provider.

  • Christian
    March 27th, 2011 at 06:49

    Hi! I fixed. I was using VS 2008 and I need VS 2010 with .net 4.0

    Thanks for all.

Who Linked To This Post?

  1. Tweets that mention Seamless support for Boolean and GUID datatypes in Firebird and Entity Framework | Jiří {x2} Činčura -- Topsy.com
  2. Firebird News » Seamless support for Boolean and GUID datatypes in Firebird and Entity Framework

Share your thoughts, leave a comment!