DataServiceRequest<TElement> Klasse
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Stellt Anforderungsobjekte dar, die als Batch an den Datendienst übermittelt werden.
generic <typename TElement>
public ref class DataServiceRequest sealed : System::Data::Services::Client::DataServiceRequest
public sealed class DataServiceRequest<TElement> : System.Data.Services.Client.DataServiceRequest
type DataServiceRequest<'Element> = class
inherit DataServiceRequest
Public NotInheritable Class DataServiceRequest(Of TElement)
Inherits DataServiceRequest
Typparameter
- TElement
- Vererbung
Beispiele
Bei ExecuteBatch Rückgabe wurde die gesamte HTTP-Antwort für die Batchanforderung aus dem Netzwerkdatenstrom gelesen, die Antworten wurden jedoch nicht verarbeitet. Die Identitätsauflösung und Objektmaterialisierung treten für eine angegebene Entität in der Antwort erst auf, wenn sie wie im folgenden Beispiel dargestellt iteriert wird.
DataServiceContext service = new DataServiceContext(new
Uri("http://myserviceroot"));
// Create query batches.
DataServiceRequest[] reqs = new DataServiceRequest[] {
new DataServiceRequest<Category>(
new Uri("http://myserviceroot/Categories")),
new DataServiceRequest<Customer>(
new Uri("http://myserviceroot/Customers"))
};
DataServiceResponse dsr;
try
{
// Client will not throw an exception on ExecuteBatch because the
// entire response has not been processed yet to know
// whether an exception should be thrown.
dsr = service.ExecuteBatch(reqs);
if (dsr.IsBatchResponse)
{
/*inspect HTTP artifacts associated with the entire batch:
dsr.BatchHeaders, dsr.BatchStatusCode*/ }
foreach (QueryOperationResponse qr in dsr)
{
if (IsErrorStatusCode(qr.StatusCode))
{
//q.Error.Message contains the full contents of the error.
/* process any part of the Error Contract (<error> element)
sent from the service. */
}
}
else
{
if (qr.Query.ElementType == typeof(Customer))
{
//process customers
foreach (Customer c in qr){ /*process the customer*/ }
// the DataServiceContext does not materialize, resolve
// identity on Customer until it is enumerated.
}
else if (qr.Query.ElementType == typeof(Category))
{
// Process categories.
foreach (Category cat in qr)
{
/*process the category*/
}
// the DataServiceContext does not materialize or
// resolve identity on the Category until
// it is enumerated.
// This means that instream errors will be thrown
// during iteration.
}
}
}
}
catch (DataServiceRequestException e)
{
// This error is thrown if the data service returns with
// a response code < 200 or >299 or the top level element.
// If neither of the above or true, this exception is not
// thrown.
dsr = e.Response;
if (dsr.IsBatchResponse)
{
/*inspect HTTP artifacts associated with the entire batch:
dsr.BatchHeaders, dsr.BatchStatusCode*/
}
/* There will always only be one of these because if the top level
status code was >=200 and =<299 and the first element was not an
error, the call to start the query will not throw. */
foreach (QueryOperationResponse qr in dsr)
{
if (qr.Error != null)
{
// Process error.
}
}
}
Hinweise
In einer Gruppe von Abfragen, die als Batch an den Datendienst gesendet werden, werden die Abfragen als DataServiceRequest<TElement> Instanzen angegeben. A DataServiceResponse wird zurückgegeben, die die Antwort der Batchanforderung als Ganzes darstellt. Einzelne Abfrageantworten werden als QueryOperationResponse Objekte dargestellt, die von OperationResponseder Instanz abgeleitet werden, auf die zugegriffen werden kann, indem sie die DataServiceResponse Instanz aufzählt.
Konstruktoren
| Name | Beschreibung |
|---|---|
| DataServiceRequest<TElement>(Uri) |
Initialisiert eine neue Instanz der DataServiceRequest<TElement>-Klasse. |
Eigenschaften
| Name | Beschreibung |
|---|---|
| ElementType |
Ruft den Typ des Objekts ab, das zum Erstellen der DataServiceRequest<TElement> Instanz verwendet wird. |
| RequestUri |
Ruft das URI-Objekt ab, das die Anforderungszeichenfolge enthält. |
Methoden
| Name | Beschreibung |
|---|---|
| Equals(Object) |
Bestimmt, ob das angegebene Objekt dem aktuellen Objekt entspricht. (Geerbt von Object) |
| GetHashCode() |
Dient als Standardhashfunktion. (Geerbt von Object) |
| GetType() |
Ruft die Type der aktuellen Instanz ab. (Geerbt von Object) |
| MemberwiseClone() |
Erstellt eine flache Kopie der aktuellen Object. (Geerbt von Object) |
| ToString() |
Stellt den URI der Abfrage für den Datendienst dar. (Geerbt von DataServiceRequest) |