score:1

Accepted answer

functions declared in the database provider are normally available under the provider's namespace. so if this was a normal entity sql query you should be able to invoke stuff() adding sqlserver before it, e.g. sqlserver.stuff(strtime, 3, 0, ':').

however, the entity sql in the body of a model-defined functions can only refer to other canonical functions or other model-defined functions, i.e. model-defined functions cannot be made provider specific by referring to provider specific functions.

this is a limitation that was adopted by choice. when your application executes a linq query you can execute provider specific functions because your application already depends on a full model with conceptual and store schemas and a mapping specification. model-defined functions on the other hand are part of the conceptual model, which is supposed to be self-contained: you should be able swap the provider, store schema or mapping specification for different ones without ever rendering the conceptual model invalid. hence things that are defined in the conceptual model cannot depend on things that are defined elsewhere.

workaround:

i did some experimentation and came up with this naïve way to simulate sql server's stuff() using only canonical functions that should work across providers. you can use something like this from your own model-defined function by specifying the namespace of the conceptual model, e.g. model1.stuff(strtime, 3, 0, ':')

<function name="stuff" returntype="string">
  <parameter name="character_expression" type="string" />
  <parameter name="start" type="int32" />
  <parameter name="length" type="int32" />
  <parameter name="replacewith_expression" type="string" />
  <definingexpression>
    left(character_expression,start-1) 
    + replacewith_expression 
    + substring(character_expression, start + length, length(character_expression))
  </definingexpression>
</function>

Related Query

More Query from same tag