There is a bug with String.Substring generating SUBSTRING instead of SUBSTR, 
which results in the SQL query failing.

Here's a way to fix this bug.

In your database model, add this code right before EntityContainer

    <Function Name="substr" Aggregate="false" BuiltIn="false" 
NiladicFunction="false" IsComposable="true" 
ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo" 
ReturnType="nvarchar">
      <Parameter Name="text" Type="nvarchar" Mode="In" />
      <Parameter Name="startPos" Type="int" Mode="In" />
    </Function>

In your context class (create a partial class next to it), add this code

    [DbFunction("MyModel.Store", "substr")]
    public string SubStr(string text, int startPos) {
        return text.Substring(startPos);
    }

In your code, call Substring in this way

    context.SubStr(text, startpos)

It will now properly map to the SUBSTR function instead of SUBSTRING! It's like 
mapping a User Defined Function, except that we map to an existing standard 
function.

This should be fixed in the source code.


Etienne

Reply via email to