Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Maxi 5 posts 25 karma points
    Sep 19, 2011 @ 23:53
    Maxi
    0

    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!

  • Søren Spelling Lund 1797 posts 2786 karma points
    Sep 21, 2011 @ 18:57
    Søren Spelling Lund
    0

    Hi Maxi,

    Which version are you on?

  • Maxi 5 posts 25 karma points
    Sep 21, 2011 @ 18:59
    Maxi
    0

    it's umbraco v 4.5.2 (Assembly version: 1.0.3891.20719)

  • Søren Spelling Lund 1797 posts 2786 karma points
    Sep 21, 2011 @ 19:01
    Søren Spelling Lund
    0

    The ActiveRecord interface will by default not return deleted objects. However, you can get at them by using the underlying repository instead.

    var catalogRepositoy = ObjectFactory.Instance.Resolve<IRepository<ProductCatalog>>();
    ProductCatalog myCatalog = catalogRepository.SingleOrDefault(x => x.Name == "MyCatalog")

    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.

  • Søren Spelling Lund 1797 posts 2786 karma points
    Sep 21, 2011 @ 22:08
    Søren Spelling Lund
    0

    Not sure you saw the post I fired off immediately after your reply. So here's a bump :)

  • Maxi 5 posts 25 karma points
    Sep 21, 2011 @ 22:24
    Maxi
    0

    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.

     

     

  • Søren Spelling Lund 1797 posts 2786 karma points
    Sep 21, 2011 @ 22:41
    Søren Spelling Lund
    0

    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.

  • Maxi 5 posts 25 karma points
    Sep 21, 2011 @ 22:57
    Maxi
    0

    ok, got it now.

    Is there any method to "resurrect" an object?

  • Søren Spelling Lund 1797 posts 2786 karma points
    Sep 26, 2011 @ 12:24
    Søren Spelling Lund
    0

    Yes.

    Catalog.Deleted = false;
    Catalog.Save(); 
Please Sign in or register to post replies

Write your reply to:

Draft