none
Datatype Conversion RRS feed

  • Question

  • I'm looking for a way to convert data from a CLR type to the underlying DB type in EF 4.2. The problem we have is a legacy database which represents data in specific formats which cannot be implicitly converted to a CLR type. For example a Boolean is Y or N and a date is an integer in the format YYYYMMDD.

    When creating my model the Boolean becomes a string and the Date an Int32. If I change the data types in the designer they I get an error (and in any case the project would not run).

    The obvious workaround is to create my own properties which contain the conversions, but this is bad because 1) of primary key issues as some of the specials are primary keys, and 2) the legacy DB has got a lot of tables and columns so the whole thing is going to become very difficult to maintain.

    Ideally I could specify a Func<> whcih performs the conversion when reading data from the database into my entities, which would have the great benefit of providing me with a clean solution and even a possibility to do some code generation for the offending columns.

    My question is: are there hooks in the API which I could use to wire up my converters, and if not is this something that may be coming in a future version of EF?

    Monday, February 13, 2012 2:22 PM

Answers

All replies