tags:

views:

112

answers:

3

I'm looking for a way to get all records where deleted is set to true on a particular table. How might I accomplish this?

Note: Using auto-generated class by SubSonic. Not T-SQL.

A: 

not a lot of detail in your question, but assuming there's a column named "deleted," it would look something like this:

select * from tableName where deleted = true
x0n
+2  A: 

The auto-generated SubSonic classes don't support querying logical deletes. But you can do this (version 2.1/2.2 syntax):

public partial class TableClassCollection
{

    public TableClassCollection LoadAll(bool suppressLogicalDeletes)
    {

          SubSonic.SqlQuery q = new SubSonic.Select(TableClass.Schema)
              .From(TableClass.Schema);

          if (suppressLogicalDeletes)
          {
              q.Where(TableClass.DeletedColumn).IsEqualTo(false);
          }

          return q.ExecuteAsCollection<TableClassCollection>();
      }

}

More examples at subsonicproject.com

ranomore
+2  A: 

I've never heard of SubSonic before, but a quick Google search turned up: Select Queries in SubSonic.

So, using that page as a guide, it sounds like you'd be able to write your query as:

FooCollection deletedFoos = // use the generated collection class
    DB.Select().From("FooTable") // table name goes here
        .Where("deleted").IsEqualTo(true) // might need 1, depends on database?
        .ExecuteAsCollection<FooCollection>(); // should match the type above
Tadmas
That's pretty good for never having heard of SubSonic before.
ranomore