Dapper

From Bitnami MediaWiki
Revision as of 11:12, 3 October 2023 by 99.255.206.241 (talk)
Jump to navigation Jump to search

Example:

var dbConn = dbContext.Database.GetDbConnection();
if (dbConn.State != ConnectionState.Open)
{
  await dbConn.OpenAsync();
}
return await dbConn.QueryAsync<FooDTO>(@"
  SELECT
    f.foo_id AS FooId,
    f.name AS Name
  FROM dbo.Foo f
  WHERE f.foo_id = @fooId
  ",
  new
  {
    fooId,
  });

Do not hard code the database name. In the service class that extends BaseService, you can call GetDatabase("id") to get the tenant database.

Stored procedure example:

return await dbConn.QuerySingleAsync<ShlSequenceDTO>(
  "usp_GetSequence",
  new
  {
    seed,
  },
  commandType: CommandType.StoredProcedure
  );

Return to Programming Guide