16
Mar

Entity Framework v4.1 Code First and Firebird

I do love Entity Framework. And you probably know it from the amount of weird ways to do some things published on this blog. And so I do love Code First. It’s like having all the power absolutely under control (or at least there’s a possibility to have it). And I also do love Firebird. It’s a great database engine. And I admit, it has strong as well weak points. But every engine does.

So there’s no wonder I’m using Entity Framework’s 4.1 (currently in CTP stage) Code First with Firebird. If you’re a bit lazy and you’re specifying only required minimum on information to run the mapping, you might quickly face one problem.

Long story. If you generated your model from database, the SSDL contained a lot of information about database structure. Especially lengths of (var)char fields. And these information were then used by provider for Firebird to create proper queries. But with Code First it’s bit boring to specify lengths for string fields moreover, when it works without it.

But the Firebird’s API has some limitations (especially around sizes of stuff) and by default (right now – CTP) the (var)char fields are 4000 characters long. The amount of (var)char parameters in code is limited (depends on few variables like charset, hence I’m not putting here exact number) and with UTF8 (multi-byte charset) it’s even more limited. And UTF8 is option #1 in .NET world.

All this together, couple of (var)char fields without length specified and you could start seeing Implementation limit exceeded and block size exceeds implementation restriction etc. The first place where you’ll see it is inserting, because there you have all the fields.

The solution is easy. Specify lengths explicitly and hope for the best. If the table is very wide (aka it doesn’t work), you could always split the table in more (yes, not great, but …).

There's 9 Comments So Far

  • Petr
    March 17th, 2011 at 09:02

    BTW: RC is available…
    http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-release-candidate-available.aspx

  • cincura.net
    March 17th, 2011 at 09:46

    I know. I have already some posts in queue.

  • Gennadiy
    March 21st, 2011 at 16:40

    Ahoj! Is there any documentation for the Firebird .NET Provider and Entity Framework Provider? Thank you.

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

    @Gennadiy: What documentation? Working with it is same as with any other EF enabled provider.

  • gregory
    July 20th, 2011 at 08:21

    There is an issue with Firebird and EF 4.1 Code First I cannot overcome.

    In you earlier example, you used existing database and Fluent API for mappings, which while possible is not ideal for me. I would want EF to create database for me reflecting my model. When I use database intializer:

    Database.SetInitializer(new DropCreateDatabaseAlways());

    With correct firebird connection string in app.config:

    (C:\test.fdb does not exist, so EF should create one for me)

    My object context usage ends up with following exception:
    ProviderIncompatibleException: The provider did not return a ProviderManifestToken string.

    Is this an issue with provider not yet implemented, or I’ve got something wrong and it sould work all right?

    PS. My FbConnection and creating firebird database programmatically from connection string works ok.

  • cincura.net
    July 20th, 2011 at 10:37

    It’s something that’s probably wrong with your environment.

  • gregory
    July 22nd, 2011 at 08:01

    I drilled down some exceptions, and it appears that Creating database through code first is impossible in firebird. Default initializers first connect to database and then call delete, so if firebird database does not exist (no .fdb file) they simply throw exception. I’ll try to find some workaraound, but it’s not looking good to be honest.

  • cincura.net
    July 22nd, 2011 at 08:11

    Depending on initializer it might by checking database existence, which is not supported on Firebird too. That might be root cause of it.

Who Linked To This Post?

  1. Firebird News » Entity Framework v4.1 Code First and Firebird

Share your thoughts, leave a comment!