I've deleted a product catalog, and now, I want to create a new one with the same name, but i can't because that name is already used. I've tried to get it using
Also I should mention that I tried deleting a catalog and recreating it with the same name without incident just now. It would be interesting to get your repro steps for the scenario.
My scenario: I created the catalog using the API and then removed it from ucommerce section. When I try to re create using the API,I get an error from SQL saying that I cannot insert a catalog with the same name due to a database index. However, if I re create the catalog using ucommerce section, it works well.
Ah yes, we call that process "resurrection". Whenever we're dealing with a deleted object we check whether it exists before creating it and "resurrect" it if it does.
There's a trick to this. If you ask for a single object uCommerce will return it to.
So ProductCatalog.SingleOrDefault(x => x.Name == "MyDeletedCatalog") will return the deleted object wheres ProductCatalog.Where(x => x.Name == "MyDeletedCatalog") will not. The idea being that when you're dealing with lists you probably don't want to remember to filter (I know we don't), but when you're asking for a specific catalog you probably want it regardless of it being marked as deleted.
How can i get the deleted entities?
Hello All!
I've deleted a product catalog, and now, I want to create a new one with the same name, but i can't because that name is already used. I've tried to get it using
ProductCatalog
.Find(c => c.Name.ToLower() == name.ToLower()).FirstOrDefault()
But the "Find" method is filtering the deleted items. Same fot All() or SingleOrDefault().
Any ideas?
Thanks in adavance!
Hi Maxi,
Which version are you on?
it's umbraco v 4.5.2 (Assembly version: 1.0.3891.20719)
The ActiveRecord interface will by default not return deleted objects. However, you can get at them by using the underlying repository instead.
Also I should mention that I tried deleting a catalog and recreating it with the same name without incident just now. It would be interesting to get your repro steps for the scenario.
Thanks.
Not sure you saw the post I fired off immediately after your reply. So here's a bump :)
yep, I saw it, thanks!
I've just tried it and It works! thank you!
My scenario: I created the catalog using the API and then removed it from ucommerce section. When I try to re create using the API,I get an error from SQL saying that I cannot insert a catalog with the same name due to a database index. However, if I re create the catalog using ucommerce section, it works well.
Ah yes, we call that process "resurrection". Whenever we're dealing with a deleted object we check whether it exists before creating it and "resurrect" it if it does.
There's a trick to this. If you ask for a single object uCommerce will return it to.
So ProductCatalog.SingleOrDefault(x => x.Name == "MyDeletedCatalog") will return the deleted object wheres ProductCatalog.Where(x => x.Name == "MyDeletedCatalog") will not. The idea being that when you're dealing with lists you probably don't want to remember to filter (I know we don't), but when you're asking for a specific catalog you probably want it regardless of it being marked as deleted.
ok, got it now.
Is there any method to "resurrect" an object?
Yes.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.