score:0

Here's are the modifications that got it working for me.

In the OnModelCreating() method, add this line:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        // ...
        modelBuilder.Conventions.Add(new FunctionsConvention("dbo", this.GetType()));
    }

When defining the DbFunction stub use these attributes:

    [DbFunction("CodeFirstDatabaseSchema", "Echo")]
    public static string Echo(string text)
    {
        throw new NotSupportedException("Direct calls are not supported.");
    }

I took ideas from this link

Here's the test I performed to see if it was the issue you were having: If I comment out the modelBuilder.Conventions.Add line above, I receive a similar error to what you were receiving.

System.NotSupportedException: 'The specified method 'System.String Echo(System.String)' on the type 'try1.ExContext' cannot be translated into a LINQ to Entities store expression.'


Related Articles