本文整理汇总了C#中System.Collections.MapODataServiceRoute方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.MapODataServiceRoute方法的具体用法?C# System.Collections.MapODataServiceRoute怎么用?C# System.Collections.MapODataServiceRoute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections
的用法示例。
在下文中一共展示了System.Collections.MapODataServiceRoute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateConfiguration
private static HttpConfiguration CreateConfiguration(IEdmModel model)
{
HttpConfiguration configuration =
new[]
{
typeof(MainEntityController), typeof(PeopleController), typeof(EnumCustomersController),
typeof(CollectionSerializerCustomersController), typeof(PresidentController)
}.GetHttpConfiguration();
configuration.MapODataServiceRoute(model);
configuration.Formatters.InsertRange(0, ODataMediaTypeFormatters.Create());
return configuration;
}
示例2: GetEntry_UsesRouteModel_ForMultipleModels
public void GetEntry_UsesRouteModel_ForMultipleModels()
{
// Model 1 only has Name, Model 2 only has Age
ODataModelBuilder builder1 = new ODataModelBuilder();
var personType1 = builder1.EntityType<FormatterPerson>();
personType1.HasKey(p => p.PerId);
personType1.Property(p => p.Name);
builder1.EntitySet<FormatterPerson>("People").HasIdLink(p => new Uri("http://link/"), false);
var model1 = builder1.GetEdmModel();
ODataModelBuilder builder2 = new ODataModelBuilder();
var personType2 = builder2.EntityType<FormatterPerson>();
personType2.HasKey(p => p.PerId);
personType2.Property(p => p.Age);
builder2.EntitySet<FormatterPerson>("People").HasIdLink(p => new Uri("http://link/"), false);
var model2 = builder2.GetEdmModel();
var config = new[] { typeof(PeopleController) }.GetHttpConfiguration();
config.MapODataServiceRoute("OData1", "v1", model1);
config.MapODataServiceRoute("OData2", "v2", model2);
using (HttpServer host = new HttpServer(config))
using (HttpClient client = new HttpClient(host))
{
using (HttpResponseMessage response = client.GetAsync("http://localhost/v1/People(10)").Result)
{
Assert.True(response.IsSuccessStatusCode);
JToken json = JToken.Parse(response.Content.ReadAsStringAsync().Result);
// Model 1 has the Name property but not the Age property
Assert.NotNull(json["Name"]);
Assert.Null(json["Age"]);
}
using (HttpResponseMessage response = client.GetAsync("http://localhost/v2/People(10)").Result)
{
Assert.True(response.IsSuccessStatusCode);
JToken json = JToken.Parse(response.Content.ReadAsStringAsync().Result);
// Model 2 has the Age property but not the Name property
Assert.Null(json["Name"]);
Assert.NotNull(json["Age"]);
}
}
}
示例3: GetEnumResponse
private HttpResponseMessage GetEnumResponse(string acceptHeader)
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<EnumCustomer>("EnumCustomers");
IEdmModel model = builder.GetEdmModel();
HttpConfiguration configuration = new[] { typeof(EnumCustomersController) }.GetHttpConfiguration();
configuration.MapODataServiceRoute("odata", routePrefix: null, model: model);
HttpServer host = new HttpServer(configuration);
HttpClient client = new HttpClient(host);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/EnumCustomers");
request.Content = new StringContent(
string.Format(@"{{'@odata.type':'#System.Web.OData.Formatter.EnumCustomer',
'ID':0,'Color':'Green, Blue','Colors':['Red','Red, Blue']}}"));
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
request.Headers.Accept.ParseAdd(acceptHeader);
HttpResponseMessage response = client.SendAsync(request).Result;
return response;
}