-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding compatibility with DateTimeOffset values in MySQL #6601
Comments
@gmartinezsan Have you tried returning the appropriate type mapping in your implementation of RelationalTypeMapper? |
hi @ajcvickers , thanks for the reply.
Thanks in advance for your time. |
@gmartinezsan As of now, EF Core only supports types that can be read from the DbDataReader with a call to |
Thanks for the information @ajcvickers .. I'm closing this issue and follow up with the #242 |
@gmartinezsan It is possible to resolve your instances of The trick for me, was intercepting how the value is materialized from the value buffer. Before:
After:
This is possible because I had implemented custom explicit operators on my
See the following gist: With trying to map Perhaps define a helper class
And then generate the mapping expression using a custom
Hopefully the work in #242 makes this somewhat easier. |
Possible with Value Conversions Define the Converter: private ValueConverter GetDateTimeToDateTimeOffsetConverter()
{
var converter = new ValueConverter<DateTimeOffset, DateTime>(
requestedWithOffset => requestedWithOffset.DateTime,
requested => new DateTimeOffset(requested, TimeSpan.Zero)
);
return converter;
} Then add it to the property: entity.Property(e => e.date)
.HasColumnName("date")
.HasColumnType("timestamp")
.HasConversion(GetDateTimeToDateTimeOffsetConverter()); |
We are trying to add DateTimeOffset support in DBContext model. This type is mapped to a Timestamp in MySQL. The issue we have is that the types are no compatibles automatically in EF. Thus we need to add some extension method or something else so the user can perhaps create a custom conversion or we can provide maybe a generic.
Is there already any methods we can override or implement in the current EF Core infraestructure?
@rowanmiller
@divega
Any comments are highly appreciated.
The text was updated successfully, but these errors were encountered: