You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
reberinformatik, ctolkien, mip1983, mikesigs, kerryarts and 371 morevbabic, pjingram33, BenjiFarquhar, GraemeSMiller and jmoralesvjsmith-jxe, jjwilliams42, ziomyslaw, MuadDib, slamotte and 27 moreSteffenMangold, bbrandt, andersonferrari, jroney, ddieppa and 8 morebbrandt, SteffenMangold, vertonghenb, neman, andersonferrari and 8 more
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.
GSPP, reberinformatik, lucasmaj, mikesigs, jjwilliams42 and 15 more
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.
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 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.
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?
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?
@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.
Activity
rowanmiller commentedon Mar 4, 2016
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:
Sql(string)
to make the table temporal.[-]Temporal Tables[/-][+]Support Temporal Tables[/+]DavidBainbridgeRIT commentedon Jun 7, 2016
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.
R00iBaard commentedon Sep 16, 2016
Agree, I would love to be able to set this up all via EF code first.
reberinformatik commentedon Sep 21, 2016
👍 See also #2229
lucasmaj commentedon Sep 28, 2016
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)
divega commentedon Sep 28, 2016
@lucasmaj have you tried raw SQL queries as a workaround as explained above? E.g. in EF6 use
SqlQuery()
andFromSql()
with EF Core. The latter is composable in LINQ.lucasmaj commentedon Sep 28, 2016
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.
ghost commentedon Mar 22, 2017
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?
R00iBaard commentedon Apr 20, 2017
Any update on this? It would be very nice to have this 👍
ajcvickers commentedon Apr 20, 2017
@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.
146 remaining items