Cosmos: Configure TTL per entity/entity type/container
AndriySvyryd opened this issue ยท 8 comments
To specify a TTL value for a given item the entity type must have a property mapped to "ttl" and the corresponding container must have a non-null TTL
Hi Team,
Is there any update on this? We need to set TTL at item level but it can work only if it is configured at container level and I couldn't find any method in efcore 3.1.1 that sets TTL value at container level. Any help would be much appreciated
Thank you
@pavitrag123 No work has been done for this yet. Vote ๐ on the first post for the features that you think should be prioritized.
Let's make it up-for-grabs.
I would try to prepare a PR for this
@Marusyk We don't use the up-for-grabs label anymore, you can submit a PR for any issue. But at this point we aren't accepting external PRs for 5.0 anymore, it would need to target main
(6.0).
Would it be possible to link where in the documentation this new functionality is explained? Couldn't find it at first glance.
There's a sample at https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-6.0/whatsnew#configure-time-to-live
I've created dotnet/EntityFramework.Docs#3730 to track this
@AndriySvyryd the sample you provided only shows a fixed, container-scoped value. I wanted to setup a "per entry" TTL value without a container default value (the "On (no default)" option).
Is there a way to also do that, or does EF only support changing this setting at model building time? I assume it's the former, in which case a very basic outline of how it works would be fine while I wait for the full documentation.
I have a project coming up where we'll allow the user to provide an expiration date that will then be the source for Cosmos TTL, so it would be essential to know whether this is possible or not.
You'd need to do something like
modelBuilder.Entity<MyEntity>().HasDefaultTimeToLive(3600).Property<int>("Ttl").ToJsonProperty("ttl");
And then
context.Entry(myEntity).Property<int>("Ttl").CurrentValue = 60
You can also use a non-shadow property to make the code simpler.