Routenpräfix überschreiben

Verwenden Sie eine Tilde für das Methodenattribut, um das Routenpräfix zu überschreiben:
C#

[RoutePrefix(„api/books“)]
public class BooksController : ApiController
{
// GET /api/authors/1/books
[Route(„~/api/authors/{authorId:int}/books“)]
public IEnumerable<Book> GetByAuthor(int authorId) { … }

// …
}

redirecting -problem

WebApiApplication -> WebApiConfig zweite config auskommentieren.

public static void Register(HttpConfiguration config)
{
// Web-API-Konfiguration und -Dienste

// Web-API-Routen
config.MapHttpAttributeRoutes();
/*
config.Routes.MapHttpRoute(
name: „DefaultApi“,
routeTemplate: „api/{controller}/{id}“,
defaults: new { id = RouteParameter.Optional }
);*/
}

genaue try catch exception

C# Exception Handling Best Practices

durch mehrere catch- blocks können (zuerst) speziellere Exceptions behandelt werden , eine geauere auswahl kann durch when erzielt werden.

WebClient wc = null;
try
{
   wc = new WebClient(); //downloading a web page
   var resultData = wc.DownloadString("http://google.com");
}
catch (WebException ex) when (ex.Status == WebExceptionStatus.ProtocolError)
{
   //code specifically for a WebException ProtocolError
}
catch (WebException ex) when ((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound)
{
   //code specifically for a WebException NotFound
}
catch (WebException ex) when ((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.InternalServerError)
{
   //code specifically for a WebException InternalServerError
}
finally
{
   //call this if exception occurs or not
   wc?.Dispose();
}

Datumsumwandlung DateTime – Zeit Problem

in c# und linq gibt es offensichtlich nur die Möglichkeit die EntityFunktions.TruncateTime zu benutzen.

Dafür muss in der Datenbank aber diese Funktion als stored-function eingetragen sein

Create FUNCTION TruncateTime(dateValue DateTime) RETURNS date
return Date(dateValue);

in der Nutzung dann :

EntityFunctions.TruncateTime(r.aktion.from_) 
<= 
EntityFunctions.TruncateTime(DateTime.Now)

Verwendet in der Zaehlererfassung.