Link to home
Start Free TrialLog in
Avatar of ram27
ram27

asked on

Error while adding the stored proc manually in Entity frame work and trying call it from Web Api

Hi i am having below issue when trying to call a stored proc from web Api , below is my code

Model:

 public class SF_Oculus_ListingsLast4Days_Vw
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public Int64? OculusListingsID { get; set; }

        public int? MLSID { get; set; }

        [StringLength(255)]
        public String MLSName { get; set; }

        [StringLength(100)]
        public String MLSAgentID { get; set; }

        [StringLength(100)]
        public String MLSOfficeID { get; set; }


Controller :

[ODataRoutePrefix("SF_Oculus_ListingsLast4Days_Vw")]
    public class SF_Oculus_ListingsLast4Days_VwController : ODataController
    {
        readonly OrdersModel _db = new OrdersModel();

        Action<OrdersModel> SetTimeOut = (OrdersModel _db) =>
        {
            if (_db != null)
                _db.Database.CommandTimeout = Constants.Constants.SqlTimeOut;
        };

        [ODataRoute]
        [EnableQuery(PageSize = 20, AllowedQueryOptions = AllowedQueryOptions.All)]
        public IHttpActionResult Get([FromODataUri] string SF_OwnerID)
        {
            SetTimeOut(_db);
            return Ok(_db.SF_Oculus_ListingsLast4Days_Vw(SF_OwnerID).AsQueryable());
        }

        //[ODataRoute("({key})")]
        [EnableQuery(PageSize = 20, AllowedQueryOptions = AllowedQueryOptions.All)]
        public IHttpActionResult Get([FromODataUri] int key, [FromODataUri] string SF_OwnerID)
        {
            SetTimeOut(_db);
            return Ok(_db.SF_Oculus_ListingsLast4Days_Vw(SF_OwnerID));
        }



Ordermodel..cs:

 public partial class OrdersModel : DbContext
    {
        public OrdersModel()
            : base("name=OrdersModel")
        {
        }

        public virtual DbSet<FileParty> FileParty { get; set; }
    public virtual System.Data.Entity.Core.Objects.ObjectResult<SF_Oculus_ListingsLast4Days_Vw> SF_Oculus_ListingsLast4Days_Vw(string SF_OwnerID)
        {
            var SF_OwnerIDParameter = new ObjectParameter("SF_OwnerID", SF_OwnerID);
            return ((System.Data.Entity.Infrastructure.IObjectContextAdapter)this).ObjectContext.ExecuteFunction<SF_Oculus_ListingsLast4Days_Vw>("DD_SalesForce_Oculus_ListingsLast4Days", SF_OwnerIDParameter);
        }


DD_salesForce_Oculus_ListingLast4days is my stored proc

webapiconfig.cs

  config.MapODataServiceRoute("odata", "odata", GetEdmModel());
            config.EnsureInitialized();

 private static IEdmModel GetEdmModel()
        {
            EntitySetConfiguration<SF_Oculus_ListingsLast4Days_Vw> SF_Oculus_ListingsLast4Days_Vws = builder.EntitySet<SF_Oculus_ListingsLast4Days_Vw>
           ("SF_Oculus_ListingsLast4Days_Vw");
           
            FunctionConfiguration SF_Oculus_ListingsLast4Days_VwDetails = SF_Oculus_ListingsLast4Days_Vws.EntityType.Collection.Function("SF_Oculus_ListingsLast4Days_VwGet");
            SF_Oculus_ListingsLast4Days_VwDetails.Parameter<string>("SF_OwnerID");
            SF_Oculus_ListingsLast4Days_VwDetails.ReturnsCollectionFromEntitySet<SF_Oculus_ListingsLast4Days_Vw>("SF_Oculus_ListingsLast4Days_Vw");
 
         return builder.GetEdmModel();
     }


   When trying to run the records from stored proc calling from odata like below

   https://test.sfservices.firstam.com/SalesForceREST/odata/SF_Oculus_ListingsLast4Days_Vw?%24filter=SF_OwnerID%20eq%20%2727005j000000C6Ya5AAF%27

  I am getting the error :

  {
  "error":{
    "code":"","message":"No HTTP resource was found that matches the request URI 'https://test.sfservices.firstam.com/SalesForceREST/odata/SF_Oculus_ListingsLast4Days_Vw?%24filter=SF_OwnerID eq '27005j000000C6Ya5AAF''."
  }
}

Can you let me know what I am missing and where is the problem.

Thanks!
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.