Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
888 views
in Technique[技术] by (71.8m points)

wcf - entity framework 4 POCO's stored procedure error - "The FunctionImport could not be found in the container"

Entity Framework with POCO Entities generated by T4 template. Added Function Import named it "procFindNumber" specified complex collection named it "NumberResult".

Here's what got generated in Context.cs file:

public ObjectResult<NumberResult> procFindNumber(string lookupvalue)
{
   ObjectParameter lookupvalueParameter;

   if (lookupvalue != null)
   {
      lookupvalueParameter = new ObjectParameter("lookupvalue", lookupvalue);
   }
   else
   {
       lookupvalueParameter = new ObjectParameter("lookupvalue", typeof(string));
   }
   return base.ExecuteFunction<NumberResult>("procFindNumber", lookupvalueParameter);
}

Here's the stored procedure:

ALTER PROCEDURE [dbo].[procFindNumber] 
@lookupvalue varchar(255)   
AS
BEGIN
SET NOCOUNT ON;    
DECLARE @sql nvarchar(MAX); 

IF @lookupvalue IS NOT NULL AND @lookupvalue <> ''
    BEGIN                   
        SELECT @sql = 'SELECT dbo.HBM_CLIENT.CLIENT_CODE, dbo.HBM_MATTER.MATTER_NAME, dbo.HBM_MATTER.CLIENT_MAT_NAME 
                FROM dbo.HBM_MATTER INNER JOIN dbo.HBM_CLIENT ON dbo.HBM_MATTER.CLIENT_CODE = dbo.HBM_CLIENT.CLIENT_CODE 
                LEFT OUTER JOIN dbo.HBL_CLNT_CAT ON dbo.HBM_CLIENT.CLNT_CAT_CODE = dbo.HBL_CLNT_CAT.CLNT_CAT_CODE 
                LEFT OUTER JOIN dbo.HBL_CLNT_TYPE ON dbo.HBM_CLIENT.CLNT_TYPE_CODE = dbo.HBL_CLNT_TYPE.CLNT_TYPE_CODE 
                WHERE (LTRIM(RTRIM(dbo.HBM_MATTER.CLIENT_CODE)) <> '''')'
        SELECT @sql = @sql + ' AND (dbo.HBM_MATTER.MATTER_NAME like ''%' + @lookupvalue + '%'')'
        SELECT @sql = @sql + ' OR (dbo.HBM_MATTER.CLIENT_MAT_NAME like ''%' + @lookupvalue + '%'')'
        SELECT @sql = @sql + ' ORDER BY dbo.HBM_MATTER.MATTER_NAME'
        -- Execute the SQL query
        EXEC sp_executesql @sql
    END 
END

In my WCF service I try to execute the stored procedure:

[WebGet(UriTemplate = "number/{value}/?format={format}")]        
public IEnumerable<NumberResult> GetNumber(string value, string format)
{
   if (string.Equals("json", format, StringComparison.OrdinalIgnoreCase))
   {
       WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Json;
   }

   using (var ctx = new MyEntities())
   {                
       ctx.ContextOptions.ProxyCreationEnabled = false;
       var results = ctx.procFindNumber(value);
       return results.ToList();
   }
}

Error message says "The FunctionImport ... could not be found in the container ..."

What am I doing wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to qualify the function import with the container name.

E.g change this:

return base.ExecuteFunction<NumberResult>("procFindNumber", lookupvalueParameter);

to this:

return base.ExecuteFunction<NumberResult>("EntityContainerName.procFindNumber", lookupvalueParameter);

The entity container name is found on your EDMX - right click anywhere and do "Properties".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...