The FunctionImport could not be found in the container

Nov 13, 2014 at 5:59 AM
I'm trying to map to a function returns a complex type. I looked at the example in E2ETest.

I created a context object extending DbContext, initialized like this:
public class MyContext : DbContext () {
 protected override void OnModelCreating(DbModelBuilder modelBuilder) {
     modelBuilder.ComplexType<Search_ResultType>();
     modelBuilder.Conventions.Add(new FunctionsConvention<MyContext>("schema1"));
     base.OnModelCreating(modelBuilder); 
 }
}

When I tried to run the following code, I'm getting a functionimport "SearchFunction" could not be found in the container MyContext. In the database, the function is in "schema1", named as SearchFunction. Can someone tell me if I missed any config or set up of context? Thanks!
  [DbFunction("MyContext", "SearchFunction")]
  public virtual ObjectResult<Search_ResultType> Search(string namefilters) {
     ObjectParameter nameFilterParameter = !string.IsNullOrWhiteSpace(namefilters)
                                              ? new ObjectParameter("Criteria", namefilters)
                                              : new ObjectParameter("Criteria", string.Empty);
     return ((IObjectContextAdapter) this).ObjectContext.ExecuteFunction<Search_ResultType>(
           "SearchFunction", nameFilterParameter);
  }
Nov 13, 2014 at 5:32 PM
I found a blog explained what I missed. http://blog.3d-logic.com/2014/04/09/support-for-store-functions-tvfs-and-stored-procs-in-entity-framework-6-1/.

I added a DbFunctionDetailAttribute and specified the schema name, made sure my method above has the same name as the function name in db.

It passed this FuncionImport not found error. However, I'm now getting a command execution exception: Invalid object name 'schema1.SearchFunction'. I'm continue to debug and see what's wrong. If anyone knows of anything that might have caused the error please let me know. Thanks!
Nov 16, 2014 at 3:14 AM
Invalid object name 'schema1.SearchFunction'. indicates that the stored procedure could not be found in the database. Are you sure it's in the schema1 schema?

Thanks,
Pawel