-
Notifications
You must be signed in to change notification settings - Fork 20
Adam edited this page May 11, 2021
·
5 revisions
It depends on your SELECT statements in the stored procedure. Use the table below to see what your return type would be.
Number of SELECT statements | Number of columns | Number of rows | Return type |
---|---|---|---|
One SELECT | One column | One row (uses TOP 1 clause) | Returns a primitive that matches the column data type. |
Many rows | Returns IEnumerable<T> where T is a primitive matching the column data type. | ||
Many columns | One row (uses TOP 1 clause) | Returns a single instance of a generated DTO object. | |
Many rows | Returns IEnumerable<T> where T is a generated DTO object. | ||
Many SELECT's | Any | Any | Returns an object with properties named "Result", "Result2", "Result3", etc. All properties are IEnumerable<T> where T is a generated DTO. |
- There are instances where a data type might not be able to be inferred by SqlSharpener and, therefore, defaults to type
Object
. I'm still working on this. The work-around for now is to wrap your code in aCAST
orCONVERT
. For example,SELECT CAST(someFunction() as int)
.
- When there are multiple select statements, DTOs will be generated for all results.
- When there are multiple columns in a select statement.
- The number of records affected.
- Yes. The class and interface are generated as partials. Also, there are partial methods at the beginning and end of each function. For example, if your stored procedure name is "TaskGet", the following partial methods will be generated:
- OnTaskGetBegin();
- OnTaskGetEnd(result);
- Implement these partial methods in your partial class to be notified when the function call begins and ends. Notice that the result gets passed to the "end" function before being returned back to the caller. This allows you to do some cool things such as audit logging. Google "partial methods" for more info on how to implement these.