Dapper: Difference between revisions
Jump to navigation
Jump to search
(Created page with "<strong>Example:</strong> <pre>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, });</pre> <strong>Do not hard code</strong> the database name. In the service class that extends BaseService, you can call GetDatabase("id") to get the ten...") |
No edit summary |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 17: | Line 17: | ||
});</pre> | });</pre> | ||
<strong>Do not hard code</strong> the database name. In the service class that extends BaseService, you can call GetDatabase("id") to get the tenant database. | <strong>Do not hard code</strong> the database name. In the service class that extends BaseService, you can call GetDatabase("id") to get the tenant database. | ||
<strong>Stored procedure example:</strong> | <strong>Stored procedure example:</strong> | ||
return await dbConn.QuerySingleAsync<ShlSequenceDTO>( | <pre>return await dbConn.QuerySingleAsync<ShlSequenceDTO>( | ||
"usp_GetSequence", | "usp_GetSequence", | ||
new | new | ||
Line 25: | Line 26: | ||
}, | }, | ||
commandType: CommandType.StoredProcedure | commandType: CommandType.StoredProcedure | ||
); | );</pre> | ||
<strong>Return to [[Programming Guide]]</strong> |
Latest revision as of 20:49, 3 October 2023
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