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

Cosmos: Configure TTL per entity/entity type/container #17307

Closed
AndriySvyryd opened this issue Aug 20, 2019 · 8 comments · Fixed by #25379
Closed

Cosmos: Configure TTL per entity/entity type/container #17307

AndriySvyryd opened this issue Aug 20, 2019 · 8 comments · Fixed by #25379
Labels
area-cosmos closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Milestone

Comments

@AndriySvyryd
Copy link
Member

AndriySvyryd commented Aug 20, 2019

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

@pavitrag123
Copy link

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

@AndriySvyryd
Copy link
Member Author

@pavitrag123 No work has been done for this yet. Vote 👍 on the first post for the features that you think should be prioritized.

@Marusyk
Copy link
Member

Marusyk commented Aug 25, 2020

Let's make it up-for-grabs.
I would try to prepare a PR for this

@AndriySvyryd
Copy link
Member Author

@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).

@ajcvickers ajcvickers modified the milestones: Backlog, 6.0.0 May 6, 2021
@AndriySvyryd AndriySvyryd changed the title Cosmos: Configure TTL per entity/entity type/collection Cosmos: Configure TTL per entity/entity type/container Jul 27, 2021
AndriySvyryd added a commit that referenced this issue Jul 31, 2021
AndriySvyryd added a commit that referenced this issue Jul 31, 2021
@AndriySvyryd AndriySvyryd added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jul 31, 2021
@AndriySvyryd AndriySvyryd removed their assignment Jul 31, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0, 6.0.0-rc1 Aug 12, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0-rc1, 6.0.0 Nov 8, 2021
@julealgon
Copy link

Would it be possible to link where in the documentation this new functionality is explained? Couldn't find it at first glance.

@AndriySvyryd
Copy link
Member Author

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

@julealgon
Copy link

@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.

@AndriySvyryd
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-cosmos closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants