Luis
Luis

Reputation: 6001

Subsonic Delete With Fluent Query Tool

In subsonic 2 we could do this:

public static void DeleteTable(SubSonic.TableSchema.Table table)
{
     new Delete().From(table).Execute();
}

How can we do the same thing in v3? I can only seem to find documentation about using generics to target a specific table in the database...I want to be able to use it with a parameter as above.

Thanks

Upvotes: 0

Views: 560

Answers (2)

saintedlama
saintedlama

Reputation: 6898

You use the SimpleRepository.DeleteMany method somehow like this

var repo = new SimpleRepository("ConnectionString");
repo.DeleteMany<YourClass>(x => true);

Or (after reading your comment) something like that

public static void DeleteTable(DatabaseTable table)
{
    new SubSonic.Query.Delete<object>(table, ProviderFactory.GetProvider());
}

The generic type "object" is used because Delete wants a Type passed, which is not used in case we create it using a table and provider.

Upvotes: 0

Luis
Luis

Reputation: 6001

I got it. This seems to do the trick:

public static void DeleteTable(DatabaseTable table)
{
     new Delete<object>(table, table.Provider).Execute();
}

Upvotes: 1

Related Questions