entity framework - Handling Errors with db.Database.SqlQuery -


I encountered a problem today, where I had a query that was unsuccessful. I use the db.Database.SqlQuery & lt; T & gt; () to query other application data, we have a custom view on their data today, the administrator has rebuilt the indexes in the software and removed custom views in this process. Although this is an issue that no one can solve, the issue you can help, they are handling this matter in a great way where there is no look.

For the main application, we are using this data as supplemental data. This means that the server or table can not be reached, it is not important to display the information. The query is running in WebApi follow-up action (I added some comments based on my observations during debugging.):

  Public work & lt; HttpResponseMessage & gt; GetByAddress (String ID) {Task & lt; HTTPRPS Pormes & gt; reaction; String sql = // my sql statement; & Lt; Object & gt; ParameterList = New List & lt; Object & gt; (); ParameterList.Add (id.ToUpper ()); Object [param] parameter = list.ToArray (); // This is useless because the following line is completely this IEnumerable & lt; CallsForService & gt; Call = new list & lt; CallForce service & gt; (); // If the table does not exist, it does not make any errors, instead it creates a different object with error descriptions. Call = db. database SQLQuery & lt; CallForce service & gt; (SKL, Ultimate); Reaction = function.formersalt & lt; HTTPRPS Pormes & gt; (Request Create Response (HTTTATS code. OK, call)); Return feedback; }  

My question is how do I check these errors and at least honestly send the calling application back to an empty list. I can log these errors with ELMAH so that I can fix this by catching this issue.

The query is not executed until the results are executed, so you only count the number of records Anyone can and can generate any error.

  calls = db.Database.SqlQuery & lt; CallsForService & gt; SQL, Ultimate); Var recCount = calls.Count ();  

Any errors raised after the last line / catch will be caught by the block.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -