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

How to set global date format conversion?not used utc #420

Closed
Angus221 opened this issue Sep 15, 2020 · 9 comments
Closed

How to set global date format conversion?not used utc #420

Angus221 opened this issue Sep 15, 2020 · 9 comments
Assignees

Comments

@Angus221
Copy link

Model

image

Code like :
.Where("RequestDate>=\"2020/08/07 00:00:00\"")

or
.Where("RequestDate>=@1",Datetime.Now)

I've tried two ways to use it, but still format as utc,
Exception
image

@JonathanMagnan JonathanMagnan self-assigned this Sep 15, 2020
@JonathanMagnan
Copy link
Member

Hello @Angus221 ,

In which format do you wish your date time? How you usually do it without LINQ Dynamic (so with purely LINQ)?

Best Regards,

Jon


Performance Libraries
context.BulkInsert(list, options => options.BatchSize = 1000);
Entity Framework ExtensionsEntity Framework ClassicBulk OperationsDapper Plus

Runtime Evaluation
Eval.Execute("x + y", new {x = 1, y = 2}); // return 3
C# Eval FunctionSQL Eval Function

@Angus221
Copy link
Author

Hello @Angus221 ,

In which format do you wish your date time? How you usually do it without LINQ Dynamic (so with purely LINQ)?

Best Regards,

Jon

Performance Libraries
context.BulkInsert(list, options => options.BatchSize = 1000);
Entity Framework ExtensionsEntity Framework ClassicBulk OperationsDapper Plus

Runtime Evaluation
Eval.Execute("x + y", new {x = 1, y = 2}); // return 3
C# Eval FunctionSQL Eval Function

I wish date time format like "yyyy/MM/dd H:mm:ss"
Puerly Linq was not thorw exception with date time in the "where" method,
the output sql query contains(Linq dynamic):
[RequesteDate] > '2019-05-10T13:03:17.0000000+02:00'
It doesn't work in the sql server.

@Angus221
Copy link
Author

Hello @Angus221 ,

In which format do you wish your date time? How you usually do it without LINQ Dynamic (so with purely LINQ)?

Best Regards,

Jon

Performance Libraries
context.BulkInsert(list, options => options.BatchSize = 1000);
Entity Framework ExtensionsEntity Framework ClassicBulk OperationsDapper Plus

Runtime Evaluation
Eval.Execute("x + y", new {x = 1, y = 2}); // return 3
C# Eval FunctionSQL Eval Function

         var config = new System.Linq.Dynamic.Core.ParsingConfig() {
                DateTimeIsParsedAsUTC = false
            };
...
 .Where(config, "view.IsDeleted=false And "RequestDate>=@0 ",Datetime.Now )

I try use config ,but it doesn't work

@Angus221
Copy link
Author

My EF version EntityframeworkCore 5.0-Preview8

@StefH
Copy link
Collaborator

StefH commented Sep 16, 2020

@Angus221 What happens if you just use normal LINQ (so not dynamic), does that work for you?

@Angus221
Copy link
Author

@Angus221 What happens if you just use normal LINQ (so not dynamic), does that work for you?

Normal LINQ has no exception,but my query columns should be configured dynamically,so I need dynamic.

Could you help me test the "datetime" type with EF Core 5-preview8 ?

@StefH
Copy link
Collaborator

StefH commented Sep 17, 2020

@Angus221
As a workaround, you could try to set the Thread.CurrentThread.CurrentCulture to the culture which will generate the correct DateTime format.

See: https://docs.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.defaultthreadcurrentculture?redirectedfrom=MSDN&view=netcore-3.1#System_Globalization_CultureInfo_DefaultThreadCurrentCulture

@Angus221
Copy link
Author

Angus221 commented Sep 18, 2020

@Angus221
As a workaround, you could try to set the Thread.CurrentThread.CurrentCulture to the culture which will generate the correct DateTime format.

See: https://docs.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.defaultthreadcurrentculture?redirectedfrom=MSDN&view=netcore-3.1#System_Globalization_CultureInfo_DefaultThreadCurrentCulture

Thanks for your reply ,I try it,but it doesn't work,still the same format.
image

@Angus221
Copy link
Author

My code still have the exception with System.Linq.Dynamic.Core 1.2.5 , why closed the issues?

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants