efcore icon indicating copy to clipboard operation
efcore copied to clipboard

SQL Server temporal tables

Open shivajiraot opened this issue 10 years ago • 113 comments

Does EF Core support code first approach for Temporal tables? Looking to find a way to use Temporal tables with EF Core code first approach. Please guide me to the article if any existing already. Thank you.

shivajiraot avatar Mar 03 '16 05:03 shivajiraot

For the most part, the fact that a table is temporal is opaque to the data layer - so from that point of view you should be fine to connect to an existing database with temporal tables.

Here are some limitations though, that we could address in EF:

  • If you wanted to query a past state of the table you would need to use a raw SQL query.
  • There is no way to make a table temporal in the model/migrations. So if you are using EF to create the database then you would need to hand edit the migration and use Sql(string) to make the table temporal.

rowanmiller avatar Mar 04 '16 21:03 rowanmiller

I second this as important. Temporal tables are fantastic. They cut out a lot of boiler plate but I need that information in the front end just as easily as in the back end.

DavidBainbridgeRIT avatar Jun 07 '16 09:06 DavidBainbridgeRIT

Agree, I would love to be able to set this up all via EF code first.

R00iBaard avatar Sep 16 '16 07:09 R00iBaard

👍 See also #2229

reberinformatik avatar Sep 21 '16 11:09 reberinformatik

I was absolutely bummed out to find out that currently there is no obvious way to query past state using lambda expressions. Is there any way to sneak in "AS OF <date_time>" into a query? (in EF6)

lucasmaj avatar Sep 28 '16 02:09 lucasmaj

@lucasmaj have you tried raw SQL queries as a workaround as explained above? E.g. in EF6 use SqlQuery() and FromSql() with EF Core. The latter is composable in LINQ.

divega avatar Sep 28 '16 03:09 divega

I haven't tried raw SQL. If EF6 had SqlQuery composable with LINQ it would do the trick for now. There is no way I would go with pure sql queries and abandon LINQ. Unless there could be a way for LINQ to pure sql back to entities in an automatic fashion.

Is there really no way to augment conversion of Expressions to SQL string so that some custom expression would translate to "AS OF" etc?

Thank you nonetheless.

lucasmaj avatar Sep 28 '16 05:09 lucasmaj

I look forward to full support of Temporal Tables in an upcoming release. In the meantime, I am trying to make use of the SysStartTime/SysEndTime columns added to the table in the model (using CodeFirst), and I find that EF is trying to write to those columns even when I have the model property annotated with DatabaseGenerated(DatabaseGeneratedOption.Computed). Is there a way to get around this issue so that I can at least use those columns added for versioning without writing SQL?

ghost avatar Mar 22 '17 23:03 ghost

Any update on this? It would be very nice to have this 👍

R00iBaard avatar Apr 20 '17 07:04 R00iBaard

@R00iBaard This issue is in the Backlog milestone. This means that it is not going to happen for the 2.0 release. We will re-assess the backlog following the 2.0 release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.

ajcvickers avatar Apr 20 '17 18:04 ajcvickers

+1, I would like to use this in the very near future for a new enterprise doc automation app that requires an audit history on every screen. Does anyone have any more information about the work around's for now?

ntimmerman avatar Jun 14 '17 15:06 ntimmerman

+1

We need it too!

Or is.there any workaround, maybe something like intercepting?

pray1997 avatar Jun 15 '17 09:06 pray1997

+1 - I hope this gets prioritized after 2.0, this would be great to have without manual setup!

ephos avatar Jul 05 '17 14:07 ephos

+1

chassq avatar Aug 22 '17 12:08 chassq

+1

kliebenberg avatar Sep 10 '17 18:09 kliebenberg

+1

aziz-builds avatar Sep 13 '17 18:09 aziz-builds

+1

cSteusloff avatar Sep 15 '17 07:09 cSteusloff

If you added support for interceptors (like in EF6), then it would be possible to handle inserts and updates to temporal tables by handling the generated fields.

squeakyD avatar Oct 04 '17 14:10 squeakyD

@squeakyD - At present you can configure your model with generated columns to insert/update data in temporal table. Main and most useful functionality would be the query pipeline especially generating SQL with between predicate etc.

smitpatel avatar Oct 04 '17 17:10 smitpatel

+1, would love to see the ability to time slice with a lambda expression.

binarypatrick avatar Oct 16 '17 20:10 binarypatrick