Skip to content
Adam edited this page May 11, 2021 · 5 revisions

Frequently asked questions

How are return types of functions generated?

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.

Why does my SELECT someFunction() return type Object?

  • 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 a CAST or CONVERT. For example, SELECT CAST(someFunction() as int).

What conditions cause a DTO to be generated?

  • When there are multiple select statements, DTOs will be generated for all results.
  • When there are multiple columns in a select statement.

What do functions return when there are no select statements?

  • The number of records affected.

Can I extend the generated class with my own functionality?

  • 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.