-
Notifications
You must be signed in to change notification settings - Fork 0
Best practices
Ian Yates edited this page Mar 25, 2022
·
3 revisions
Lists of best practices in regards to performance, correctness, and quality, as learned through use of the framework.
- Use the "gateway" or "repository" patterns to remove direct Pho/rm requests from your business logic.
- If "nullable reference types" is enabled for your project, you can safely assume that
Get<T[]>
(get array) will never returnnull
.
The suggested syntax is thereforeGet<T[]>()!
.
Provider-specific suggestions will be tagged, where known.
- One contract per action.
- Use a prefix to distinguish stored procedures and views from tables. Pho/rm suggests
usp_
andvw_
by default. - Name stored procedures clearly. i.e.,
GetDataByKey
,GetAllData
. - Do not use
SELECT *
to access data; this removes protection against underlying structural changes (see our ethos). -
[T-SQL] Start procedures with
SET NOCOUNT ON
to remove unnecessary performance overhead and network traffic.
If you need the affected rows count for a particular query, you can print/raiserror the@@ROWCOUNT
value as needed. -
[T-SQL] If you are using transactions within a procedure, start the procedure with
SET XACT_ABORT ON
to further protect data integrity. - All contracts have an accessible
int
return value. Given that the default will be0
if omitted, the same as non-execution, it is recommended to use a standard non-0
value for success (e.g.,1
) for actions that are not returning a meaningful result value, so that it can still be tested for success.
All examples here useRETURN 1
to indicate success. - Use negative results to return unique errors/validation failures per stored procedure.