Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

date/time value generator + .net conversion - #436

#436
Open
Strandedpirate wants to merge 3 commits into
loresoft:masterloresoft/EntityFrameworkCore.Generator:masterfrom
Strandedpirate:feature/value-generatorStrandedpirate/EntityFrameworkCore.Generator:feature/value-generatorCopy head branch name to clipboard
Open

date/time value generator + .net conversion#436
Strandedpirate wants to merge 3 commits into
loresoft:masterloresoft/EntityFrameworkCore.Generator:masterfrom
Strandedpirate:feature/value-generatorStrandedpirate/EntityFrameworkCore.Generator:feature/value-generatorCopy head branch name to clipboard

Conversation

@Strandedpirate

@Strandedpirate Strandedpirate commented Apr 8, 2023

Copy link
Copy Markdown

.Net & EF don't handle UTC date/time columns correctly out of the box. By default all date/time objects are created in .Net using DateTimeKind.Local.

This request:

  • allows the definition of a global date/time value generator.
  • allows the definition of a global date/time kind.

EFG Configuration

mapping:
  namespace: "{Project.Namespace}.Domain.EntityConfiguration"
  directory: '{Project.Directory}\My.Domain\EntityConfiguration'
  document: false
  dateTimeKind: Utc # configures the conversion of date/time columns as UTC in .Net
  dateTimeDefaultValueGenerator: UtcValueGenerator # defines the default date/time value generator

Produces

builder.Property(t => t.CreatedOn)
    .IsRequired()
    .HasColumnName("CreatedOn")
    .HasColumnType("datetime2(1)")
    .HasDefaultValueSql("(sysutcdatetime())")
    .HasConversion(t => t, t => DateTime.SpecifyKind(t, DateTimeKind.Utc))
    .HasValueGenerator<UtcValueGenerator>();

Sample UtcValueGenerator

internal class UtcValueGenerator : ValueGenerator<DateTime>
{
    public override bool GeneratesTemporaryValues => false;

    public override DateTime Next([NotNullAttribute] EntityEntry entry)
    {
        return DateTime.UtcNow;
    }
}

@Strandedpirate

Copy link
Copy Markdown
Author

@pwelter34 what do you think about this pull request?

@github-actions

Copy link
Copy Markdown
Contributor

⏰ Stale Pull Request

No activity for 1 year. Will close in 45 days unless updated.
To keep open, push commits, comment, or remove the stale label.

@github-actions github-actions Bot added the stale label Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.