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

Dynamic query on timestamptz #697

Closed
emaborsa opened this issue Mar 30, 2023 · 6 comments
Closed

Dynamic query on timestamptz #697

emaborsa opened this issue Mar 30, 2023 · 6 comments
Assignees
Labels

Comments

@emaborsa
Copy link

emaborsa commented Mar 30, 2023

Hi all,
my Model has a DateTime property:

public class Appointment : Item
{
    public int ClientId { get; set; }
    public int? OperatorId { get; set; }
    public DateTime Date { get; set; }
    public decimal From { get; set; }
    public decimal To { get; set; }
    public string Notes { get; set; }

    public virtual Client Client { get; set; }
    public virtual Operator Operator { get; set; }
}

The DatabaseContext:

entity.Property(e => e.Date)
  .HasColumnType("timestamptz")
  .IsRequired()
  .HasColumnName("date");

I am using dynamic Linq query, I simply use a where condition over a iQueryable:

iQueryable.Where(condition);

The condition is fully dynamic, I build it based on the passed parametes. If the parameter is a filter for the Date property I don't really know how the query should be. I tried Date == "2023-03-30T00:00:00.000Z" and Date == DateTime.Parse("2023-03-30T00:00:00.000Z") I get:

'timestamp with time zone' literal cannot be generated for Local DateTime: a UTC DateTime is required.

The database field is a timestamptz. I already tried adding the attribute as mentioned here, did not help.

How has the condition to look like?

@StefH
Copy link
Collaborator

StefH commented May 20, 2023

Maybe use something like:

var x = dbcontext.Appointments.Where("Date == @0", DateTime.Parse("2023-03-30T00:00:00.000Z").ToUniversalTime());

@StefH
Copy link
Collaborator

StefH commented Aug 15, 2023

@emaborsa
Did this answer help you?

@emaborsa
Copy link
Author

Sorry, I have not been able to check it yet.

@StefH
Copy link
Collaborator

StefH commented Oct 29, 2023

@emaborsa
Did you have time to check?

@emaborsa
Copy link
Author

Unfortunately I didnt, have to work on another project.

@StefH StefH self-assigned this Nov 26, 2023
@StefH StefH added the question label Nov 26, 2023
@StefH
Copy link
Collaborator

StefH commented Nov 26, 2023

I'm closing this now.

In case you still have an issue, comment here or create a new issue.

@StefH StefH closed this as completed Nov 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants