本文整理汇总了C#中ODataConventionModelBuilder.EnableLowerCamelCase方法的典型用法代码示例。如果您正苦于以下问题:C# ODataConventionModelBuilder.EnableLowerCamelCase方法的具体用法?C# ODataConventionModelBuilder.EnableLowerCamelCase怎么用?C# ODataConventionModelBuilder.EnableLowerCamelCase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ODataConventionModelBuilder
的用法示例。
在下文中一共展示了ODataConventionModelBuilder.EnableLowerCamelCase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetModel
public override IEdmModel GetModel(Type elementClrType, HttpRequestMessage request,
HttpActionDescriptor actionDescriptor)
{
// Get model for the request
IEdmModel model = request.ODataProperties().Model;
if (model == null)
{
// user has not configured anything or has registered a model without the element type
// let's create one just for this type and cache it in the action descriptor
model = actionDescriptor.Properties.GetOrAdd("System.Web.OData.Model+" + elementClrType.FullName, _ =>
{
ODataConventionModelBuilder builder =
new ODataConventionModelBuilder(actionDescriptor.Configuration, isQueryCompositionMode: true);
builder.EnableLowerCamelCase();
EntityTypeConfiguration entityTypeConfiguration = builder.AddEntityType(elementClrType);
builder.AddEntitySet(elementClrType.Name, entityTypeConfiguration);
IEdmModel edmModel = builder.GetEdmModel();
Contract.Assert(edmModel != null);
return edmModel;
}) as IEdmModel;
}
Contract.Assert(model != null);
return model;
}
示例2: ConfigureWebApi
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureWebApi(IAppBuilder app)
{
var config = new HttpConfiguration();
// Web API routes
config.MapHttpAttributeRoutes(); //NB Must come before OData route mapping
config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional });
// OData: Create the OData model. Here, we're using the convention model builder that will use OData
// convention defaults for model creation and routing.
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
// All entity properties should be in lower camel case
builder.EnableLowerCamelCase();
// Because PersonSearchHit inherits from SearchHit, we'll ignore it.
// This gets around the convention builder's decision to create an entity out of the SearchHit object.
builder.Ignore<PersonSearchHit>();
// Create two entity sets:
// One for search features and one that will retrieve a given person.
builder.EntitySet<IndexSearch>("Search");
builder.EntitySet<Person>("People");
// OData model registration and route creation
config.MapODataServiceRoute("ODataRoute", null, builder.GetEdmModel());
// Set up the bearer token that will be required to do OData calls.
WebApiConfigBearerToken.Configure(config);
app.UseWebApi(config);
}
示例3: GetConventionModel
public static IEdmModel GetConventionModel()
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
EntitySetConfiguration<Employee> employees = builder.EntitySet<Employee>("Employees");
EntityTypeConfiguration<Employee> employee = employees.EntityType;
employee.EnumProperty<Gender>(e => e.Sex).Name = "Gender";
employee.Collection.Function("GetEarliestTwoEmployees").ReturnsCollectionFromEntitySet<Employee>("Employees");
var functionConfiguration = builder.Function("GetAddress");
functionConfiguration.Parameter<int>("id");
functionConfiguration.Returns<Address>();
var actionConfiguration = builder.Action("SetAddress");
actionConfiguration.Parameter<int>("id");
actionConfiguration.Parameter<Address>("address");
actionConfiguration.ReturnsFromEntitySet(employees);
var resetDataSource = builder.Action("ResetDataSource");
builder.Namespace = typeof(Employee).Namespace;
builder.EnableLowerCamelCase();
var edmModel = builder.GetEdmModel();
return edmModel;
}
示例4: Register
public static void Register(HttpConfiguration config)
{
config.EnableCors();
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Exercise>("Exercises");
builder.EntitySet<Workout>("Workouts");
builder.EntitySet<WorkoutSession>("WorkoutSessions");
builder.EntitySet<ExerciseSet>("ExerciseSets");
builder.EnableLowerCamelCase();
// Need this. Otherwise SingleResult<WorkoutSession> GetWorkoutSession tries to return null and then fails to serialize the null value.
config.MapODataServiceRoute(
"odata"
, "odata"
, builder.GetEdmModel()
, defaultHandler: HttpClientFactory.CreatePipeline(
innerHandler: new HttpControllerDispatcher(config)
, handlers: new[] { new ODataNullValueMessageHandler() }));
}
示例5: Register
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// TOOD: change it in production
var cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
var builder = new ODataConventionModelBuilder();
builder.EnableLowerCamelCase();
config.Formatters.Add(new FlatFormatter(new QueryStringMapping("$format", "flat", "application/json")));
builder.EntitySet<Namespace>("Namespaces");
builder.EntitySet<Translation>("Translations");
config.MapODataServiceRoute(
routeName: "ODataRoute",
routePrefix: null,
model: builder.GetEdmModel());
}
示例6: GenerateEdmModel
private static IEdmModel GenerateEdmModel()
{
var builder = new ODataConventionModelBuilder();
builder.EnableLowerCamelCase();
builder.EntitySet<TranslatedVideo>("Videos");
return builder.GetEdmModel();
}
示例7: GetCustomRouteModel
private static IEdmModel GetCustomRouteModel()
{
var builder = new ODataConventionModelBuilder();
builder.EnableLowerCamelCase();
builder.EntitySet<Customer>("Customers");
builder.EntitySet<Order>("Orders");
return builder.GetEdmModel();
}
示例8: GetEdmModel
private static IEdmModel GetEdmModel()
{
var builder = new ODataConventionModelBuilder();
builder.EntitySet<ProjectSimpleResponseModel, SearchController>();
builder.EntityType<ProjectSimpleResponseModel>().Property(x => x.ShortDate);
builder.EntityType<ProjectSimpleResponseModel>().Property(x => x.TitleUrl);
builder.Namespace = typeof(ProjectSimpleResponseModel).Namespace;
builder.EnableLowerCamelCase();
return builder.GetEdmModel();
}
示例9: GetEdmModel
private static IEdmModel GetEdmModel()
{
var builder = new ODataConventionModelBuilder {Namespace = typeof (Log).Namespace};
builder.EntitySet<Log>("logs");
builder.EntitySet<Logs_Full.Result>("logs_full");
builder.EntitySet<Application>("applications");
builder.EntitySet<Environment>("environments");
builder.EntitySet<DataSource>("dataSources");
builder.EnableLowerCamelCase();
var edmModel = builder.GetEdmModel();
return edmModel;
}
示例10: GetEdmModel
private static IEdmModel GetEdmModel()
{
var builder = new ODataConventionModelBuilder();
builder.EntitySet<Brand>("Brands");
builder.EnableLowerCamelCase(NameResolverOptions.ProcessReflectedPropertyNames | NameResolverOptions.ProcessExplicitPropertyNames);
builder.EntityType<Brand>().Ignore(brand => brand.Name);
return builder.GetEdmModel();
}
示例11: GenerateEdmModel
private static IEdmModel GenerateEdmModel()
{
var builder = new ODataConventionModelBuilder();
builder.EnableLowerCamelCase();
builder.EntitySet<TranslatedComment>("Comments");
builder.EntitySet<TranslatedAbuse>("Abuses");
// TOOD: check why when I added lines below - author is no longer navigation property and I don't have to use: $expand=author
builder.Namespace = "Actions";
builder.EntityType<TranslatedComment>().Action("VoteUp").Parameter<VoteUp>("vote");
builder.EntityType<TranslatedComment>().Action("VoteDown").Parameter<VoteDown>("vote");
builder.EntityType<TranslatedComment>().Action("ReportAbuse").Parameter<Report>("report");
return builder.GetEdmModel();
}
示例12: GenerateEdmModel
private static IEdmModel GenerateEdmModel()
{
var builder = new ODataConventionModelBuilder();
builder.EnableLowerCamelCase();
builder.EntitySet<Suggestion>("Suggestions");
builder.EntitySet<VoteUp>("VotesUp");
builder.EntitySet<VoteDown>("VotesDown");
builder.EntitySet<View>("Views");
builder.Namespace = "Actions";
builder.EntityType<Suggestion>().Action("VoteUp").Parameter<VoteUp>("vote");
builder.EntityType<Suggestion>().Action("VoteDown").Parameter<VoteDown>("vote");
builder.EntityType<Suggestion>().Action("CountView").Parameter<View>("view");
return builder.GetEdmModel();
}
示例13: GetModel
public static IEdmModel GetModel()
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
EntitySetConfiguration<Employee> employees = builder.EntitySet<Employee>("Employees");
EntityTypeConfiguration<Employee> employee = employees.EntityType;
employee.EnumProperty<Gender>(e => e.Sex).Name = "Gender";
var resetDataSource = builder.Action("ResetDataSource");
builder.Namespace = typeof(Employee).Namespace;
// All the property names in the generated Edm Model will become camel case if EnableLowerCamelCase() is called.
builder.EnableLowerCamelCase();
var edmModel = builder.GetEdmModel();
return edmModel;
}
示例14: Register
public static void Register( HttpConfiguration config )
{
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefaultHostAuthentication();
config.Filters.Add( new HostAuthenticationFilter( OAuthDefaults.AuthenticationType ) );
config.MapHttpAttributeRoutes();
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EnableLowerCamelCase();
builder.EntitySet<Session>( "Sessions" );
var userEntityType = builder.EntitySet<Account>( "Users" ).EntityType;
userEntityType.Ignore( e => e.Claims );
userEntityType.Ignore( e => e.Logins );
userEntityType.Ignore( u => u.Password );
builder.EntitySet<Profile>( "Profiles" );
config.MapODataServiceRoute(
"odata",
"odata",
builder.GetEdmModel(),
new ODataNullValueMessageHandler()
{
InnerHandler = new HttpControllerDispatcher( config )
} );
// Web API routes
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
示例15: GetFunctionsEdmModel
private static IEdmModel GetFunctionsEdmModel()
{
var builder = new ODataConventionModelBuilder();
builder.EnableLowerCamelCase();
builder.EntitySet<Product>("Products");
var productType = builder.EntityType<Product>();
// Function bound to a collection that accepts an enum parameter
var enumParamFunction = productType.Collection.Function("GetByEnumValue");
enumParamFunction.Parameter<MyEnum>("EnumValue");
enumParamFunction.ReturnsCollectionFromEntitySet<Product>("Products");
// Function bound to an entity set
// Returns the most expensive product, a single entity
productType.Collection
.Function("MostExpensive")
.Returns<double>();
// Function bound to an entity set
// Returns the top 10 product, a collection
productType.Collection
.Function("Top10")
.ReturnsCollectionFromEntitySet<Product>("Products");
// Function bound to a single entity
// Returns the instance's price rank among all products
productType
.Function("GetPriceRank")
.Returns<int>();
// Function bound to a single entity
// Accept a string as parameter and return a double
// This function calculate the general sales tax base on the
// state
productType
.Function("CalculateGeneralSalesTax")
.Returns<double>()
.Parameter<string>("state");
// Function bound to an entity set
// Accepts an array as a parameter
productType.Collection
.Function("ProductsWithIds")
.ReturnsCollectionFromEntitySet<Product>("Products")
.CollectionParameter<int>("Ids");
// An action bound to an entity set
// Accepts multiple action parameters
var createAction = productType.Collection.Action("Create");
createAction.ReturnsFromEntitySet<Product>("Products");
createAction.Parameter<string>("Name").OptionalParameter = false;
createAction.Parameter<double>("Price").OptionalParameter = false;
createAction.Parameter<MyEnum>("EnumValue").OptionalParameter = false;
// An action bound to an entity set
// Accepts an array of complex types
var postArrayAction = productType.Collection.Action("PostArray");
postArrayAction.ReturnsFromEntitySet<Product>("Products");
postArrayAction.CollectionParameter<ProductDto>("products").OptionalParameter = false;
// An action bound to an entity
productType.Action("Rate")
.Parameter<int>("Rating");
return builder.GetEdmModel();
}