The FunctionImport 'GetEmployee' could not be found in the container 'CtxDb'

Viewed 10579

I'm trying to call a stored procedure by using Linq. For that I wrote this code:

 public class CtxDb:DbContext
    {
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

        }
        public virtual ObjectResult<Employee> GetEmployee()
        {
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<Employee>("GetEmployee");
        }
    }

When I'm calling my sp from Web API I'm getting an error:

The FunctionImport 'GetEmployee' could not be found in the container 'CtxDb'

2 Answers

I hope this will help you

public virtual IEnumerable<GetProductCategoryList_Result> GetProductCategoryList(Nullable<int> userID)
{
    var userIDParameter = userID.HasValue ?
        new SqlParameter("UserID", userID) :
        new SqlParameter("UserID", System.Data.SqlDbType.Int);

    //return this.Database.SqlQuery<GetProductCategoryList_Result>("GetProductCategoryList @UserID", userIDParameter).ToList();
    return ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreQuery<GetProductCategoryList_Result>("osa.GetProductCategoryList @UserID", userIDParameter);
}
Related