locked
How to loop through a array of id's RRS feed

  • Question

  • User-1449468620 posted

    I am trying to pass multiple id's to return a zip file of documents.

    I am getting a error

    {"The argument types 'Edm.Int32' and 'Edm.String' are incompatible for this operation. Near WHERE predicate, line 1, column 82."}

    stacktrace

       at System.Data.Entity.Internal.Linq.InternalSet`1.FindInStore(WrappedEntityKey key, String keyValuesParamName)
       at System.Data.Entity.Internal.Linq.InternalSet`1.Find(Object[] keyValues)
       at System.Data.Entity.DbSet`1.Find(Object[] keyValues)
       at TransparentEnergy.ControllersAPI.apiZipPipeLineController.Get(String[] id) in e:\Development\TransparentEnergy\TransparentEnergy\ControllersAPI\BatchZipApi\apiZipPipeLineController.cs:line 25
       at lambda_method(Closure , Object , Object[] )
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)

    apicontroller

     public HttpResponseMessage Get([FromUri] string[] id)
            {
                var documents = new List<Document>();
                using (var context = new ApplicationDbContext())
                {
                    foreach (string doc in id)
                    {
                        Document document = context.Documents.Find(new object[] { doc });
                        if (document == null)
                        {
                            throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
                        }
    
                        documents.Add(document);
                    }
    
                    using (var zipFile = new ZipFile())
                    {
                        // Make zip file
                        foreach (var d in documents)
                        {
                            var dt = d.DocumentDate.ToString("y").Replace('/', '-').Replace(':', '-');
                            string fileName = String.Format("{0}-{1}-{2}.pdf", dt, d.PipeName, d.LocationAb);
                            zipFile.AddEntry(fileName, d.DocumentUrl);
                        }
    
                        return ZipContentResult(zipFile);
                    }
                }
            }

    watch

    screenshot

    Wednesday, April 1, 2015 8:19 AM

Answers

All replies