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

Posted by user331884 on Stack Overflow See other posts from Stack Overflow or by user331884
Published on 2011-02-03T23:23:31Z Indexed on 2011/02/03 23:25 UTC
Read the original article Hit count: 1187

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?

© Stack Overflow or respective owner

Related posts about wcf

Related posts about stored-procedures