The SqlMethod attribute is used to indicate the determinism and data access properties of a method or a property on a UDT. For a property, the SqlMethod attribute should be used on the setter or the getter directly. The SqlMethod attribute contains a set of properties that include all the SqlFunction properties, and adds two new properties.
Note: |
|---|
|
The SqlMethodAttribute class inherits from the SqlFunctionAttribute class, so SqlMethodAttribute inherits the FillRowMethodName and TableDefinition fields from SqlFunctionAttribute. This implies that it is possible to write a table-valued method, which is not the case. The method compiles and the assembly deploys, but an error about the IEnumerable return type is raised at runtime with the following message: "Method, property, or field '<name>' in class '<class>' in assembly '<assembly>' has invalid return type."
|
SqlMethod [ ( method-attribute [ ,... ] ) ]
method-attribute::=
IsDeterministic= { true | false }, default is false
| IsPrecise= {true | false}
| IsMutator = { true | false }
| OnNullCall = { true | false }
| InvokeIfReceiverIsNull= { true | false }, default is false
| DataAccess = { DataAccessKind.None | DataAccessKind.Read }
| SystemDataAccess = { SystemDataAccessKind.None | SystemDataAccessKind.Read }
| FillRowMethodName= string
| Name= string
| TableDefinition= string
If IsDeterministic is set to true, the method or property is marked accordingly. The default is false.
If OnNullCall is specified, the value true indicates the method is called when NULL arguments are supplied in the method invocation. False indicates a NULL value should be assumed as the result of the method if any of its inputs is NULL. The default value of OnNullCall is true.
If the IsMutator property is set to true and the return type of the method is void, SQL Server marks the method as a mutator. A mutator method is one that causes a state change in the UDT instance. Mutator methods can be called in assignment statements or data modification statements, but cannot be used in queries. If a method is marked as a mutator but does not return void, then CREATE TYPE does not fail with an error. Even though returning a value other than void does not raise an error, the returned value is not accessible and cannot be used. The default value is false. A property can be a mutator if the SqlMethod attribute is used on the setter and IsMutator is set to TRUE. However, a property setter is implicitly treated as a mutator and it is not necessary to set the IsMutator property of the SqlMethod attribute to TRUE.
The default value for InvokeIfReceiverIsNull is false. That is, the method is not invoked on a null instance. If InvokeIfReceiverIsNull is true, the return value of the method depends upon its type. If the return type of the method is nullable, the distinguished null value for the type is returned. If the return type is non-nullable, the default CLR value for the type is returned. The default value for reference types is null, while the default value for value types is the result of calling the default constructor for the type.