Skip to content

Allow forcing DateTime parameters to DateTime or DateTime2#1147

Closed
ajcvickers wants to merge 1 commit intorelease/6.3from
TeaForTwo0815
Closed

Allow forcing DateTime parameters to DateTime or DateTime2#1147
ajcvickers wants to merge 1 commit intorelease/6.3from
TeaForTwo0815

Conversation

@ajcvickers
Copy link
Copy Markdown
Contributor

Fixes #578

Introduces an attribute which can be placed on a DbContext:

[ForceDateTimeType(DbType.DateTime)]
public class BloggingContext : DbContext
{
}

that will then cause all parameters used with this context type to be forced to the given DateTime type.

@ajcvickers ajcvickers requested review from bricelam and divega August 15, 2019 20:19
@ajcvickers
Copy link
Copy Markdown
Contributor Author

Note: this is based on the workaround posted by @stasones on the issue that seems to have been successful for people.

Fixes #578

Introduces an attribute which can be placed on a `DbContext`:

```C#
[ForceDateTimeType(DbType.DateTime)]
public class BloggingContext : DbContext
{
}
```
that will then cause all parameters used with this context type to be forced to the given DateTime type.
@ajcvickers ajcvickers removed the request for review from bricelam August 19, 2019 17:30
Copy link
Copy Markdown
Contributor

@divega divega left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at this and talked to @ajcvickers:

  1. The workaround that this PR adds to the product code (an interceptor that changes the parameter type) is already available to customers and simple enough.

  2. As a fix, this also feels very limited because it cannot handle a mix of columns that are DateTime and DateTime2 in the same database.

Even if I am not sure we are going to implement a better fix, my recommendation is to move this as a workaround to the documentation and not take this change.

@ajcvickers
Copy link
Copy Markdown
Contributor Author

@divega Sounds good; I concur.

@AlexChongMicrosoft
Copy link
Copy Markdown

Hi, I see this good fix. Does it mean our users could use it directly in our EF 6.3?

@AlexChongMicrosoft
Copy link
Copy Markdown

Hi @ajcvickers , how are you? I tried to modify my demo but seems it doesn't work. Is there something I missed? Thank you for attention.

image

@ajcvickers
Copy link
Copy Markdown
Contributor Author

@AlexChongMicrosoft Yes, you missed that we decided to not make this change.

@AlexChongMicrosoft
Copy link
Copy Markdown

@ajcvickers Thanks a lot. So it makes sense that I couldn't apply this in my demo. Thank you for attention.

@younghaiqing
Copy link
Copy Markdown

@AlexChongMicrosoft Yes, you missed that we decided to not make this change.

Hello,I want to know how u to deal this problem?

@younghaiqing
Copy link
Copy Markdown

Fixes #578

Introduces an attribute which can be placed on a DbContext:

[ForceDateTimeType(DbType.DateTime)]
public class BloggingContext : DbContext
{
}

that will then cause all parameters used with this context type to be forced to the given DateTime type.

Hello,I want to know how u to deal this problem?

@ajcvickers ajcvickers deleted the TeaForTwo0815 branch April 22, 2021 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants