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

Error With Temporals using InMemory Provider #27587

Closed
gafken opened this issue Mar 7, 2022 · 8 comments
Closed

Error With Temporals using InMemory Provider #27587

gafken opened this issue Mar 7, 2022 · 8 comments
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported

Comments

@gafken
Copy link

gafken commented Mar 7, 2022

When I'm using the InMemory Provider for EfCore 6.0 it keeps telling me that 'Example.SysStart' cannot be found. That's actually accurate as SysStart only exists on the ExampleHist Table. With the standard SQL Provider we run into no issues running our configuration. If I add the properties to the entity the InMemory Provider works fine but the SQL Provider complains that a shadow property cannot be explicitly defined.

entity.HasComment("Irrelevant Comment.")
                .ToTable(tb => tb.IsTemporal(ttb =>
    {
        ttb.UseHistoryTable("ExampleHist", "scExample");
        ttb.HasPeriodStart("SysStart") //error here
            .HasColumnName("SysStart");
        ttb
            .HasPeriodEnd("SysEnd")
            .HasColumnName("SysEnd");
    }));
The property 'Example.SysStart' could not be found. Ensure that the property exists and has been included in the model.
at IReadOnlyEntityType.GetProperty(String name)
at IMutableEntityType.GetProperty(String name)
at TemporalPeriodPropertyBuilder.HasColumnName(String name)
at <>c.<Configure>b__0_22(TemporalTableBuilder`1 ttb) line 19
at SqlServerTableBuilderExtensions.IsTemporal[TEntity](TableBuilder`1 tableBuilder, Action`1 buildAction)
at <>c.<Configure>b__0_0(TableBuilder`1 tb) line 16
at RelationalEntityTypeBuilderExtensions.ToTable[TEntity](EntityTypeBuilder`1 entityTypeBuilder, Action`1 buildAction)
at ExampleConfiguration.Configure(EntityTypeBuilder`1 entity) line 15

and

"Period property 'Example.SysStart' must be a shadow property."
@roji
Copy link
Member

roji commented Mar 7, 2022

Temporal tables are a feature of SQL Server, and are not supported in the InMemory provider. I'd recommend reading this doc page on the different testing strategies - we generally discourage using the InMemory provider.

@gafken
Copy link
Author

gafken commented Mar 8, 2022

We're not trying to test our Database/Connection, we just need a way to check that the logic operates in our codebase via unit tests. I'd be perfectly fine with a solution that ignores the temporal configuration altogether for inmemory, so long as it doesn't throw an error because of the configuration.

Just to reiterate, this is for Unit Testing and in no way are we relying on it for persistence or context maintenance.

@ajcvickers
Copy link
Member

@gafken Why do you need to use the in-memory provider for that?

@roji
Copy link
Member

roji commented Mar 8, 2022

@gafken you can add the missing temporal properties as shadow properties only for InMemory by doing a provider check when configuring the model, e.g.:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    if (Database.IsInMemory())
    {
        modelBuilder.Entity<SomeEntityType>(b =>
        {
            b.Property<DateTime>("SysStart");
            b.Property<DateTime>("SysEnd");
        });
    }
}

@gafken
Copy link
Author

gafken commented Mar 8, 2022

@roji That solved my issue, thanks a bunch! :)

@gafken gafken closed this as completed Mar 8, 2022
@roji roji added the closed-no-further-action The issue is closed and no further action is planned. label Mar 8, 2022
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
@bluebaroncanada
Copy link

Is that acceptable? Those files need to be overwriteable and autogenerated; right?

@ajcvickers
Copy link
Member

@bluebaroncanada If you're scaffolding the DbContext code, then use the partial method instead.

@iSatishYadav
Copy link

@gafken you can add the missing temporal properties as shadow properties only for InMemory by doing a provider check when configuring the model, e.g.:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    if (Database.IsInMemory())
    {
        modelBuilder.Entity<SomeEntityType>(b =>
        {
            b.Property<DateTime>("SysStart");
            b.Property<DateTime>("SysEnd");
        });
    }
}

Thanks @gafken, this worked for me as well. One side note, I had to add this code before:

base.OnModelCreating(modelBuilder);

Saved my day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported
Projects
None yet
Development

No branches or pull requests

5 participants