I was wondering if the Model.Content.Id field is a good unique identifier, will it ever change? The reason why I am asking this is because I am adding disqus comments onto my site and it requires a unique id.
It will not usually change under normal circumstances. Here are the scenarios I can think of that would cause it to change:
You migrate between two environments (e.g., staging to production) using Courier. While the underlying GUID remains the same, Courier may change the node ID.
You delete the node and then recreate it. This would be a new node, though it may in most other ways appear to be identical to the previous node.
It might be worthwhile to intercept the node creation event and automatically populate an editable "Disqus ID" field. That way, if you ever need to recreate a node or if you migrate between environments, you could retain the same ID. That's probably overkill, as those situations are probably not likely an issue with most setups. Unless you are really worried, I'd just go with the node ID (as you have suggested).
It'll likely change if data is moved between environments, whether that's via Courier, Package installer or something similar. It won't change in the current environment.
If you don't see that in intellisense, it may be because it's an extension method in Umbraco.Web.PublishedContentExtensions. As an alternative, this should also work:
var guid = (Model.Content as IPublishedContentWithKey).Key;
That is essentially what that extension method is doing.
My guess is the old way was to use the content service to obtain the GUID. However, that hits the database. So I suppose the new addition allows for the GUID to be accessed from the cache rather than hitting the database.
Also, one may be required to republish/rebuild/reindex for the new way of accessing the GUID to work (on installations that were upgraded from older version of Umbraco). Just thought I'd mention that in case somebody comes across this post in the future and it isn't quite working out for them.
Is the Model.Content.Id a good unique identifier
Hi
I was wondering if the Model.Content.Id field is a good unique identifier, will it ever change? The reason why I am asking this is because I am adding disqus comments onto my site and it requires a unique id.
Thanks
It will not usually change under normal circumstances. Here are the scenarios I can think of that would cause it to change:
It might be worthwhile to intercept the node creation event and automatically populate an editable "Disqus ID" field. That way, if you ever need to recreate a node or if you migrate between environments, you could retain the same ID. That's probably overkill, as those situations are probably not likely an issue with most setups. Unless you are really worried, I'd just go with the node ID (as you have suggested).
It'll likely change if data is moved between environments, whether that's via Courier, Package installer or something similar. It won't change in the current environment.
Ok sounds good.
Thanks
Maybe guid's would be a better idea. How do I retrieve the guid I can't seem to find it in the docs.
Thanks,
Try this:
If you don't see that in intellisense, it may be because it's an extension method in Umbraco.Web.PublishedContentExtensions. As an alternative, this should also work:
That is essentially what that extension method is doing.
By the way, this technique is apparently very new (just released on Umbraco 7.3.0): http://issues.umbraco.org/issue/U4-7038
My guess is the old way was to use the content service to obtain the GUID. However, that hits the database. So I suppose the new addition allows for the GUID to be accessed from the cache rather than hitting the database.
Also, one may be required to republish/rebuild/reindex for the new way of accessing the GUID to work (on installations that were upgraded from older version of Umbraco). Just thought I'd mention that in case somebody comes across this post in the future and it isn't quite working out for them.
Thank you very much, seems to solve my problem.
is working on a reply...