本文整理汇总了C#中ODataClient类的典型用法代码示例。如果您正苦于以下问题:C# ODataClient类的具体用法?C# ODataClient怎么用?C# ODataClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataClient类属于命名空间,在下文中一共展示了ODataClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EntityTracker
internal EntityTracker(ODataClient oDataClient, object entity)
{
Contract.Requires<ArgumentNullException>(oDataClient != null);
Contract.Requires<ArgumentNullException>(entity != null);
_oDataClient = oDataClient;
_entity = entity;
_entityTypeInfo = oDataClient.GetEntityTypeInfoFor(entity.GetType());
if (_entityTypeInfo == null)
{
throw new ArgumentException("Entity type " + entity.GetType() + " is unknown in the OData Client.");
}
_linkCollectionTrackers = new LinkCollectionTracker[_entityTypeInfo.CollectionProperties.Length];
for (int i = 0; i < _entityTypeInfo.CollectionProperties.Length; ++i)
{
PropertyInfo property = _entityTypeInfo.CollectionProperties[i];
IEnumerable collection = (IEnumerable) property.GetValue(_entity, null);
if (collection != null)
{
_linkCollectionTrackers[i] = new LinkCollectionTracker(this, property.Name, collection);
}
}
INotifyPropertyChanged inpc = _entity as INotifyPropertyChanged;
if (inpc != null)
{
// Use change tracking for more efficiency (possibly)
inpc.PropertyChanged += OnPropertyChanged;
}
}
示例2: FindEntryNuGetV1
public async Task FindEntryNuGetV1()
{
var client = new ODataClient("http://nuget.org/api/v1");
var package = await client.FindEntryAsync("Packages?$filter=Title eq 'EntityFramework'");
Assert.NotNull(package["Id"]);
Assert.NotNull(package["Authors"]);
}
示例3: FindAllPeople
public async Task FindAllPeople()
{
var client = new ODataClient(new ODataClientSettings
{
BaseUri = _serviceUri,
IncludeAnnotationsInResults = true
});
var annotations = new ODataFeedAnnotations();
int count = 0;
var people = await client
.For<PersonWithAnnotations>("Person")
.FindEntriesAsync(annotations);
count += people.Count();
while (annotations.NextPageLink != null)
{
people = await client
.For<PersonWithAnnotations>()
.FindEntriesAsync(annotations.NextPageLink, annotations);
count += people.Count();
foreach (var person in people)
{
Assert.NotNull(person.Annotations.Id);
Assert.NotNull(person.Annotations.ReadLink);
Assert.NotNull(person.Annotations.EditLink);
}
}
Assert.Equal(count, annotations.Count);
}
示例4: RetrieveSchemaFromUrlWithoutFilename
public void RetrieveSchemaFromUrlWithoutFilename()
{
var client = new ODataClient("http://vancouverdataservice.cloudapp.net/v1/impark");
var schema = client.Schema;
Assert.IsTrue(schema.Tables.Any());
}
示例5: TypedCombinedConditionsFromODataOrg
public void TypedCombinedConditionsFromODataOrg()
{
var client = new ODataClient("http://services.odata.org/V2/OData/OData.svc/");
var product = client
.For<ODataOrgProduct>("Product")
.Filter(x => x.Name == "Bread" && x.Price < 1000)
.FindEntry();
Assert.AreEqual(2.5m, product.Price);
}
示例6: AddProduct
static void AddProduct(Default.Container container, ODataClient.OData.Models.Product product)
{
container.AddToProducts(product);
var serviceResponse = container.SaveChanges();
foreach (var operationResponse in serviceResponse)
{
Console.WriteLine("Response: {0}", operationResponse.StatusCode);
}
}
示例7: AllEntriesFromODataOrg
public void AllEntriesFromODataOrg()
{
var client = new ODataClient("http://services.odata.org/V3/OData/OData.svc/");
var products = client
.For("Product")
.FindEntries();
Assert.IsNotNull(products);
Assert.AreNotEqual(0, products.Count());
}
示例8: CombinedConditionsFromODataOrg
public void CombinedConditionsFromODataOrg()
{
var client = new ODataClient("http://services.odata.org/V3/OData/OData.svc/");
var x = ODataFilter.Expression;
var product = client
.For("Product")
.Filter(x.Name == "Bread" && x.Price < 1000)
.FindEntry();
Assert.Equal(2.5m, product["Price"]);
}
示例9: GetEntryNonExistingIgnoreException
public void GetEntryNonExistingIgnoreException()
{
var settings = new ODataClientSettings
{
UrlBase = _serviceUri,
IgnoreResourceNotFoundException = true,
};
var client = new ODataClient(settings);
Assert.Null(client.GetEntry("Products", new Entry() { { "ProductID", -1 } }));
}
示例10: SyncWithAllFailures
public void SyncWithAllFailures()
{
using (var batch = new ODataBatch(_serviceUri))
{
var client = new ODataClient(batch);
client.InsertEntry("Products", new Entry() { { "UnitPrice", 10m } }, false);
client.InsertEntry("Products", new Entry() { { "UnitPrice", 20m } }, false);
Assert.Throws<WebRequestException>(() => batch.Complete());
}
}
示例11: AsyncWithPartialFailures
public async Task AsyncWithPartialFailures()
{
using (var batch = new ODataBatch(_serviceUri))
{
var client = new ODataClient(batch);
await client.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test1" }, { "UnitPrice", 10m } }, false);
await client.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test2" }, { "UnitPrice", 10m }, { "SupplierID", 0xFFFF } }, false);
Assert.Throws<WebRequestException>(() => batch.Complete());
}
}
示例12: DynamicCombinedConditionsFromODataOrg
public void DynamicCombinedConditionsFromODataOrg()
{
var client = new ODataClient("http://services.odata.org/V2/OData/OData.svc/");
var x = ODataDynamic.Expression;
var product = client
.For(x.Product)
.Filter(x.Name == "Bread" && x.Price < 1000)
.FindEntry();
Assert.AreEqual(2.5m, product.Price);
}
示例13: AllEntriesFromODataOrg
public void AllEntriesFromODataOrg()
{
AsyncContext.Run (async () =>
{
var client = new ODataClient("http://services.odata.org/V3/OData/OData.svc/");
var products = await client
.For("Product")
.FindEntriesAsync();
Assert.IsNotNull(products);
Assert.AreNotEqual(0, products.Count());
});
}
示例14: FindSinglePersonWithEntryAnnotations
public async Task FindSinglePersonWithEntryAnnotations()
{
var client = new ODataClient(new ODataClientSettings
{
BaseUri = _serviceUri,
IncludeAnnotationsInResults = true
});
var person = await client
.For<PersonWithAnnotations>("Person")
.Filter(x => x.UserName == "russellwhyte")
.FindEntryAsync();
Assert.NotNull(person.Annotations.Id);
}
示例15: AsyncWithSuccess
public async Task AsyncWithSuccess()
{
using (var batch = new ODataBatch(_serviceUri))
{
var client = new ODataClient(batch);
await client.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test1" }, { "UnitPrice", 10m } }, false);
await client.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test2" }, { "UnitPrice", 20m } }, false);
batch.Complete();
}
var product = await _client.FindEntryAsync("Products?$filter=ProductName eq 'Test1'");
Assert.NotNull(product);
product = await _client.FindEntryAsync("Products?$filter=ProductName eq 'Test2'");
Assert.NotNull(product);
}