2

In my project I use Entity Framework as my data access layer. I create a stored procedure InitPartitionStorePos and imported it. When I call the corresponding function like this:

public virtual ObjectResult<Nullable<int>> InitPartitionStorePos(Nullable<int> maxPos, string machineCode)
{
   var maxPosParameter = maxPos.HasValue ?
        new ObjectParameter("maxPos", maxPos) :
        new ObjectParameter("maxPos", typeof(int));

    var machineCodeParameter = machineCode != null ?
        new ObjectParameter("machineCode", machineCode) :
        new ObjectParameter("machineCode", typeof(string));

    return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<Nullable<int>>("InitPartitionStorePos", maxPosParameter, machineCodeParameter);
}

It throws an exception:

The FunctionImport 'InitPartitionStorePos' could not be found in the container 'PartitionEntities'

Using the code below prints nothing

ObjectContext ctx = ((IObjectContextAdapter)this).ObjectContext;

MetadataWorkspace space = ctx.MetadataWorkspace;
EntityContainer ct;

space.TryGetEntityContainer(ctx.DefaultContainerName, DataSpace.CSpace, out ct);    

foreach(EdmFunction candidate in ct.FunctionImports)
{
    System.Diagnostics.Debug.WriteLine(candidate.Name);
}

The edmx file:

enter image description here

I want to know why the EF6 could not find the import function?

I'm using Visual Studio Community 2015. The Entity Framework version is 6.1.3.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
John Zhu
  • 1,009
  • 11
  • 11

0 Answers0