本文整理汇总了C#中System.Web.Http.OData.Builder.ODataConventionModelBuilder.Entity方法的典型用法代码示例。如果您正苦于以下问题:C# ODataConventionModelBuilder.Entity方法的具体用法?C# ODataConventionModelBuilder.Entity怎么用?C# ODataConventionModelBuilder.Entity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Http.OData.Builder.ODataConventionModelBuilder
的用法示例。
在下文中一共展示了ODataConventionModelBuilder.Entity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Register
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
var newFormater = new CsvTextMediaFormatter();
newFormater.MediaTypeMappings.Add(new QueryStringMapping("frmt", "fwt", new MediaTypeHeaderValue("text/plain")));
config.Formatters.Add(newFormater);
config.Formatters.JsonFormatter.MediaTypeMappings.Add(
new QueryStringMapping("frmt", "json",
new MediaTypeHeaderValue("application/json")));
config.Formatters.XmlFormatter.MediaTypeMappings.Add(
new QueryStringMapping("frmt", "xml",
new MediaTypeHeaderValue("application/xml")));
// Serialize les types complexes qui sont rattachés à l'objet
//var json = config.Formatters.JsonFormatter;
//json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
//config.Formatters.Remove(config.Formatters.XmlFormatter);
// New code:
// Odata
ODataModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Individual>("Individuals");
builder.EntitySet<Contract>("Contracts");
ODataHttpRouteCollectionExtensions.MapODataRoute(config.Routes, routeName: "ODataRoute", routePrefix: "odata", model: builder.GetEdmModel());
builder.Entity<Individual>().Ignore(item => item.Contracts);
builder.Entity<Contract>().Ignore(item => item.Individual);
}
示例2: ModelBuilder
internal static void ModelBuilder(ODataConventionModelBuilder builder)
{
var EntitySetName = "Jobs";
builder.EntitySet<Job>(EntitySetName);
builder.Entity<Job>().Action("Run").Returns<String>();
builder.Entity<Job>().Action("Finish").Returns<String>();
}
示例3: ModelBuilder
internal static void ModelBuilder(ODataConventionModelBuilder builder)
{
var EntitySetName = "LifeCycles";
builder.EntitySet<LifeCycle>(EntitySetName);
builder.Entity<LifeCycle>().Action("Next").Returns<String>();
builder.Entity<LifeCycle>().Action("Cancel").Returns<String>();
builder.Entity<LifeCycle>().Action("Allow").Returns<String>();
builder.Entity<LifeCycle>().Action("Decline").Returns<String>();
}
示例4: GetModel
private static IEdmModel GetModel()
{
ODataModelBuilder builder = new ODataConventionModelBuilder();
builder.ContainerName = "Container";
builder.Namespace = "org.odata";
// Action with no overloads
builder.EntitySet<Vehicle>("Vehicles").EntityType.Action("Drive");
// Valid overloads of "Wash" bound to different entities
builder.Entity<Motorcycle>().Action("Wash");
builder.Entity<Car>().Action("Wash");
// Invalid overloads of "Park"
builder.Entity<Car>().Action("Park");
builder.Entity<Car>().Action("Park").Parameter<string>("mood");
return builder.GetEdmModel();
}
示例5: Register
public static void Register( HttpConfiguration config ) {
config.EnableCors();
config.MapHttpAttributeRoutes();
// To prevent Error: Self referencing loop
config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize;
config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<IUser>( "Users" );
builder.EntitySet<WebUser>( "WebUsers" );
builder.EntitySet<Guest>( "Guests" );
builder.EntitySet<Login>( "LoginSet" );
builder.EntitySet<Permission>( "PermissionSet" );
builder.EntitySet<Role>( "RoleSet" );
builder.EntitySet<Address>( "AddressSet" );
builder.EntitySet<Credential>( "CredentialSet" );
builder.EntitySet<Task>( "TaskSet" );
builder.Namespace = "OdataApi.Controllers";
builder.Entity<WebUser>().Action( "Post" ).Parameter<int>( "Rating" );
config.Routes.MapODataServiceRoute( "odata", "odata", builder.GetEdmModel() );
}
示例6: GetInheritanceModel
private static IEdmModel GetInheritanceModel(HttpConfiguration config)
{
ODataModelBuilder builder = new ODataConventionModelBuilder(config);
var baseEntitySet = builder.EntitySet<BaseEntity>("BaseEntity");
var derivedEntityType = builder.Entity<DerivedEntity>().DerivesFrom<BaseEntity>();
return builder.GetEdmModel();
}
示例7: Register
public static void Register(HttpConfiguration config)
{
// standard Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
// OData
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Customer>("Customers");
builder.EntitySet<Invoice>("Invoices");
// OData Action
ActionConfiguration purchase = builder.Entity<Customer>().Action("Purchase");
purchase.Parameter<int>("AmountOfShoes");
purchase.ReturnsFromEntitySet<Invoice>("Invoices");
config.Routes.MapODataServiceRoute("odata", "odata", builder.GetEdmModel());
// OData with fixed metadata
// see: http://www.getbreezenow.com/documentation/odata-server
config.Routes.MapODataServiceRoute("odataFixed", "odataFixed", EdmBuilder.GetEdm<DataContext>(), new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));
}
示例8: GetModel
private static IEdmModel GetModel()
{
ODataModelBuilder builder = new ODataConventionModelBuilder();
var pets = builder.EntitySet<Pet>("Pets");
builder.Entity<BigPet>();
return builder.GetEdmModel();
}
示例9: CreateCustomerContext
internal static ODataQueryContext CreateCustomerContext()
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<QueryCompositionCustomer>("Customer");
builder.Entity<QueryCompositionCustomerBase>();
IEdmModel model = builder.GetEdmModel();
return new ODataQueryContext(model, typeof(QueryCompositionCustomer));
}
示例10: GetCustomersModel
private static IEdmModel GetCustomersModel()
{
HttpConfiguration configuration = new HttpConfiguration();
configuration.Services.Replace(typeof(IAssembliesResolver), new TestAssemblyResolver(typeof(QueryCompositionCustomer)));
ODataConventionModelBuilder builder = new ODataConventionModelBuilder(configuration);
builder.EntitySet<QueryCompositionCustomer>("Customer");
builder.Entity<QueryCompositionCustomerBase>();
return builder.GetEdmModel();
}
示例11: GetModel
private static IEdmModel GetModel()
{
ODataModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<AROCustomer>("AROCustomers");
builder.Entity<AROVipCustomer>().DerivesFrom<AROCustomer>();
builder.EntitySet<AROAddress>("AROAddresses");
builder.EntitySet<AROOrder>("Orders");
return builder.GetEdmModel();
}
示例12: ShouldIgnoreStaticProperty
public void ShouldIgnoreStaticProperty()
{
ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
modelBuilder.Entity<ImplicitModelBuilder_EntityWithStaticProperty>();
var model = modelBuilder.GetEdmModel();
var actual = model.SchemaElements.Where(e => e.Name == typeof(ImplicitModelBuilder_EntityWithStaticProperty).Name).OfType<EdmEntityType>().Single();
Assert.Equal(1, actual.Properties().Count());
}
示例13: GetModel
private static IEdmModel GetModel()
{
ODataModelBuilder builder = new ODataConventionModelBuilder();
EntitySetConfiguration<Customer> customers = builder.EntitySet<Customer>("Customers");
EntityTypeConfiguration<VipCustomer> vipCustoemer = builder.Entity<VipCustomer>().DerivesFrom<Customer>();
EntitySetConfiguration<Order> orders = builder.EntitySet<Order>("Orders");
EntitySetConfiguration<Address> address = builder.EntitySet<Address>("Addresses");
EntitySetConfiguration<PersonalInformation> information = builder.EntitySet<PersonalInformation>("Informations");
return builder.GetEdmModel();
}
示例14: GetEdmModel
private static IEdmModel GetEdmModel(HttpConfiguration configuration)
{
ODataModelBuilder builder = new ODataConventionModelBuilder(configuration);
EntitySetConfiguration<SingleResultCustomer> customers = builder.EntitySet<SingleResultCustomer>("SingleResultCustomers");
EntitySetConfiguration<SingleResultOrderDetail> orderDetails = builder.EntitySet<SingleResultOrderDetail>("SingleResultOrderDetail");
EntityTypeConfiguration<SingleResultPremiumCustomer> premiumCustomer = builder.Entity<SingleResultPremiumCustomer>();
customers.EntityType.Action("CreditRating").Returns<double>();
EntitySetConfiguration<SingleResultOrder> orders = builder.EntitySet<SingleResultOrder>("SingleResultOrder");
EntitySetConfiguration<SingleResultBonus> bonuses = builder.EntitySet<SingleResultBonus>("SingleResultBonus");
IEdmModel model = builder.GetEdmModel();
return model;
}
示例15: Register
public static void Register(HttpConfiguration config)
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Product>("Products");
builder.EntitySet<Supplier>("Suppliers");
builder.EntitySet<ProductRating>("Ratings");
ActionConfiguration rateProduct = builder.Entity<Product>().Action("RateProduct");
rateProduct.Parameter<int>("Rating");
rateProduct.Returns<double>();
config.Routes.MapODataRoute("odata", "odata", builder.GetEdmModel());
}