Simple.Data

Simple.Data is a lightweight framework that uses the dynamic features of .NET 4 to provide an expressive, ORM-ish way of accessing and manipulating data without any of the code pre-generation and boilerplate required by other frameworks.

Delete

The Delete and DeleteAll methods allows the deletion of data already in your database.

The return value of an Delete method is a row or rowSet of data that has just been deleted.

You can Delete using two forms, Named arguments and using the primary key with the By clause.

Delete (Named Parameters)

    _db.Users.Delete(Id: 1);     

Generates the following SQL

    @p0 = 1
    delete from [dbo].[Users] where [dbo].[Users].[Id] = @p0

Delete (By)

    _db.Users.DeleteById(1);             

Generates the following SQL

    @p0 = 1
    delete from [dbo].[Users] where [dbo].[Users].[Id] = @p0

DeleteAll

The DeleteAll method allows a user more control over the WHERE clause on your delete statement. You may omit the WHERE clause entirely (thus causing an delete on a whole table) or you may specify criteria to delete a set within your table. There are two forms of specifying a criteria, by named arguments or by passing in an expression.

DeleteAll (with no Where clause)

_db.Users.DeleteAll();         

Generates the following SQL

delete from [dbo].[Users]

DeleteAll (with criteria)

_db.Users.DeleteAll(_db.Users.Age > 42);       

Generates the following SQL

@p0 = 42
delete from [dbo].[Users] where [dbo].[Users].[Age] > @p0

DeleteAll (with criteria, complex example)

_db.Users.DeleteAll(_db.Users.Age > 42 && _db.Users.Name.Like("J%"));     

Generates the following SQL

@p0 = 42
@p1 = 'J%'
delete from [dbo].[Users] where ([dbo].[Users].[Age] > @p1 AND [dbo].[Users].[Name] LIKE @p2)