SubSonic Forums
All Your Database Are Belong To Us

IsDeleted?

Latest post 08-25-2008 3:07 AM by Juergen. 6 replies.
  • 08-20-2008 7:06 PM

    IsDeleted?

    How do you make use of a IsDeleted column?   I have a users table, but the user.delete function throws an exception "Invalid syntax near" User.  I think that may be due to that being a keyword, but without the IsDeleted column, the .Delete method works.  Please help explain what needs to be done to allow SubSonic set that flag and the query only pull "Non-Deleted" users.  I have found no documentation on this.

     

    Thanks...

  • 08-20-2008 7:51 PM In reply to

    Re: IsDeleted?

    This should be a non null - bit column

    And you use it like this

    User user = new User(1);
    user.Delete();

    UserCollection userColl = new UserCollection().Where(User.Column.IsDeleted, false).Load();

    If I am I because I am I, and You are You because You are You, then I am I, and you are you. But If I am I because You are You, and You are You because I am I, then I am not I and You are not You. -Rabbi of Kotzk

  • 08-20-2008 11:45 PM In reply to

    • ranomore
    • Top 10 Contributor
    • Joined on 11-05-2007
    • Salt Lake City
    • Posts 322

    Re: IsDeleted?

    yitzchok:
    Where(User.Column.IsDeleted, false)

    In 2.1 you don't even need this part Angel

     

  • 08-21-2008 10:42 AM In reply to

    Re: IsDeleted?

    Good one I didn't know about it.

    Thanks

    If I am I because I am I, and You are You because You are You, then I am I, and you are you. But If I am I because You are You, and You are You because I am I, then I am not I and You are not You. -Rabbi of Kotzk

  • 08-22-2008 12:59 AM In reply to

    Re: IsDeleted?

    I was under the impression that some additional logic would be created by SubSonic to mark the record deleted and not delete.  Is this the case?  I hadn't had a chance to give that a shot yet as I was getting an incorrect syntax error.

  • 08-24-2008 12:18 AM In reply to

    • ranomore
    • Top 10 Contributor
    • Joined on 11-05-2007
    • Salt Lake City
    • Posts 322

    Re: IsDeleted?

    That's right. If you're table has a column named "Deleted" or "IsDeleted", subsonic will set the value of that column to true instead of physically deleting the record. If this is the case and you really need to physically delete the row, you can call a Destroy() method.

  • 08-25-2008 3:07 AM In reply to

    Re: IsDeleted?

    In a one to many relation I use the deleted column as a flag for deleted "many" items.

    When the user saves his changes I destroy every Deleted Column before calling MyTableCollection.SaveAll()

    You Can also do something like this:
    mytablecollection col = new mytablecollection().Load();  //loads all elements of the table
    col.Remove( col[0] );  // Remove first item of the collection
    col.ProcessDeletedItems(); // Calls Delete for every removed Item

    Note: ProcessDeletedItems is, unlike SaveAll(), not in the scope of an transaction.

    By the way: It would be nice to have the deleted or isdeleted column added to the table with
    Migrations: AddSubSonicStateColumns(TableObject);
    like the created and modified ones.

Page 1 of 1 (7 items) | RSS