entity framework - EntityFramework: Access database-column using user defined Type -


I used an old database called "inherited" where the dates are stored as Int32 values ​​( Even the time, but dates for this example would be sufficient) i.e. 20090101 for the year 2009 I can not change the schema of this database because it is still used by older programs.
Still I want to write a new program in the form of O / RM using OFR.
Now I would like to consider the date time in my model

Is there a way to write a custom type and use it as a type in EF-model

A type of properties like "OldDate" with something like:
Database Value: Int23
Value: DateTime (time-division is always 0:00:00 when specifying time-portion)

Is it possible with some EF-models? Edit:
I think what I got - but in NHibernate, so I'm lean: is there anything like EFI is possible with NHIbernates IUserType?

A can manage this I have created a type LeagcyDate Which stores the int value in the DbData property and adds an underlying conversion from date to and after it. This approach seems to be fair management as the EF4 complex type is supported in the model-designer, so by adding, no one will tamper with ADMX.

I made the underlying conversion in such a partial class:

  public partial class inheritance date {public stable underlying operator date time (? Legacy date value) {return legacy converter ToDate (value.DbData); } Public stable built-in operator legacy date (datetime? Value) {new legacy date {DbData = LegacyDateConverter.ToLegacyDate (value)}; }} Internal Fixed Class Virus DataController {Public static date time? ToDate (int data) {if (Data == 0) returns; Int Year = Data / 10000; Int. Month = (Data% 10000) / 100; Int day = data / 1000000; Date time date; {Date = New date time (year, month, day); } Hold (exception e) {new argument expression (string.format ("value can not be changed by date {0}", data), e); }             return date; } Public stable int ToLegacyDate (DateTime? Value) {int dateInt = 0; If (value.HasValue) {dateInt = value.Value.Year * 10000 + value.Value.Month * 100 + value.Value.Day; } Date of return; }}  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -