Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
WebApi not returning expected data
Message
De
18/06/2014 11:47:47
 
 
À
18/06/2014 10:34:06
Information générale
Forum:
ASP.NET
Catégorie:
Entity Framework
Versions des environnements
Environment:
C# 4.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01602038
Message ID:
01602040
Vues:
43
J'aime (1)
>There's nothing stopping you from using Code First with an existing database.
>
>Fire up Fiddler and watch the traffic to see exactly what URL is being called, the data sent, and what's returned.
>
>
>>Hi,
>>
>>I've spent a couple weeks looking at the training courses on PluralSight and have a bit better understanding of Entity Framework and Web API stuff now. I am following through a John Papa course (http://pluralsight.com/training/Courses/TableOfContents/spa) and trying to adapt it to use EF Database First rather than Code First (since I have my database defined already). I think I've got that to work.
>>
>>When it comes to writing my controllers and actually pulling data, I am not getting any data returned when I do
>>
>>http://localhost:51673/api/scancodes
>>or
>>http://localhost:51673/api/scancodes/1
>>
>>ScanCodes is just a simple table in my database with a primary key and a code and it has one record in it with primary key 1.
>>
>>The first call above returns an empty array (displays on the page like this: [])
>>
>>And the second call stops on the throw line in my code in Visual Studio with this error:
>>
>>
System.Web.Http.HttpResponseException was unhandled by user code
>>  HResult=-2146233088
>>  Message=Processing of the HTTP request resulted in an exception. Please see the HTTP response returned by the 'Response' property of this exception for details.
>>  Source=IBCPackageTracking.Web
>>  StackTrace:
>>       at IBCPackageTracking.Web.Controllers.ScanCodesController.Get(Int32 id) in d:\Documents\Visual Studio 2013\Projects\IBCPackageTracking.Web\IBCPackageTracking.Web\Controllers\ScanCodesController.cs:line 31
>>       at lambda_method(Closure , Object , Object[] )
>>       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)
>>       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
>>       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.<ExecuteAsync>b__4()
>>       at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)
>>  InnerException: 
>>
>>
>>This is my code in the ScanCodesController class:
>>
>>
        // GET api/scancodes
>>        public IEnumerable<ScanCode> Get()
>>        {
>>            return Uow.ScanCodes.GetAll().OrderBy(s => s.scn_desc);
>>        }
>>
>>        // GET api/scancodes/5
>>        public ScanCode Get(int id)
>>        {
>>            var scanCode = Uow.ScanCodes.GetById(id);
>>            if (scanCode != null) return scanCode;
>>            throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
>>        }
>>
>>I am at a loss as to where to look to work out why it is not finding my data. Any suggestions?

A tutorial on doing Code First to an existing database can be found here: http://msdn.microsoft.com/en-us/data/jj200620
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform