Skip to content
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

ValueConverter for entity. #32222

Closed
xvxzvxzvxvzxcusernamegithubav opened this issue Nov 3, 2023 · 5 comments
Closed

ValueConverter for entity. #32222

xvxzvxzvxvzxcusernamegithubav opened this issue Nov 3, 2023 · 5 comments

Comments

@xvxzvxzvxvzxcusernamegithubav

Given an table:

MyEntity
{
   public MyEnum MyType { get; set; }
   public DateTime MyDateTime { get; set; }
}

I need to change the MyDateTime on reading and writing based on MyType I would try a ValueConverter<DateTime,DateTime> but this value converter has no acces to the MyType.

How can I do this?

I did try to find some previous questions but for me it's not really clear whether this is possible or not.

@ajcvickers
Copy link
Contributor

@xvxzvxzvxvzxcusernamegithubav Can you show what code you want to write and what should happen in the database when it executes?

@xvxzvxzvxvzxcusernamegithubav
Copy link
Author

I just want to get all entities from the database. But based on the type I want to add one day to the date. (Basically to align different types of entities from some legacy systems). This would work with a converter if it was for all entities:

public class MyConverter: ValueConverter<DateTime, DateTime>
{
    public MyConverter() : base(x => x.AddDays(1), x=>x.AddDays(-1))
    {
    }
}

And of course I can run this after or while querying the data but I would like to be completely ignorant of it in my code. I would like to have a single point of definition for this offset.

@ajcvickers
Copy link
Contributor

@xvxzvxzvxvzxcusernamegithubav This isn't currently supported by value converters, but is tracked by #12205. Please vote (👍) for that issue.

@ajcvickers
Copy link
Contributor

Duplicate of #12205

@ajcvickers ajcvickers marked this as a duplicate of #12205 Nov 6, 2023
@xvxzvxzvxvzxcusernamegithubav
Copy link
Author

Ok, i hope this scenario is covered by the duplicate.

@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants