-
Notifications
You must be signed in to change notification settings - Fork 128
Home
Steven England edited this page Jan 7, 2017
·
66 revisions
#### Usage
```c#
using Dapper.FastCrud
OrmConfiguration.DefaultDialect = SqlDialect.MsSql|MySql|SqLite|PostgreSql
```
### Insert
### Delete
### Count
### Async
Async methods have an identical usage
### Options
For more information, please check the following sections: - Installation - Entity registration - Multiple mappings - SQL statements and clauses - Default library conventions - JOINs
dbConnection.Insert(newEntity);
newEntity
will have its properties partially updated with the db generated values on return
dbConnection.Get(new Asset {Id = 10});
dbConnection.Find<Entity>();
dbConnection.Find<Entity>(statement => statement
.Where($"{nameof(Entity.FirstName):C}=@FirstNameParam")
.OrderBy($"{nameof(Entity.LastName):C} DESC")
.Skip(10)
.Top(20)
.WithParameters(new {FirstNameParam = "John"});
:C is a string formatter, refer to SQL statements and clauses for available formatters.
### UpdatedbConnection.Update(updatedEntity);
updatedEntity
will have its properties partially updated with the db generated values on return
dbConnection.BulkUpdate(new Asset {Name = "Unknown"});
dbConnection.BulkUpdate(new Asset {IsLost = true}, statement => statement
.Where(@"{nameof(Asset.Name):C}='Unknown'"));
dbConnection.Delete(new Asset {Id = 10});
dbConnection.BulkDelete<Entity>();
dbConnection.BulkDelete<Asset>(statement => statement
.Where($"{nameof(Asset.IsLost):C}=1"));
dbConnection.Count<Entity>();
dbConnection.Count<Asset>(statement => statement
.Where($"{nameof(Asset.Name):C}=@AssetNameParam")
.WithParameters(new {AssetNameParam=assetName}));
### Options
As you've noticed in the previous examples, a number of options are immediately available for tweaking the statement. Their availability varies by type of operation.
- WithTimeout() - Note: the default timeout can be set instead via OrmConfiguration.DefaultSqlStatementOptions
- AttachToTransaction()
- WithEntityMappingOverride()
- Top()
- OrderBy()
- Skip()
- StreamResults()
- Where()
- WithParameters()
e.g.:
dbConnection.Insert(entityToInsert, statement =>statement
.AttachToTransaction(dbTransaction)
.WithTimeout(TimeSpan.FromSeconds(10)));
For more information, please check the following sections: - Installation - Entity registration - Multiple mappings - SQL statements and clauses - Default library conventions - JOINs