本文整理汇总了C#中ODataConventionModelBuilder.Function方法的典型用法代码示例。如果您正苦于以下问题:C# ODataConventionModelBuilder.Function方法的具体用法?C# ODataConventionModelBuilder.Function怎么用?C# ODataConventionModelBuilder.Function使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ODataConventionModelBuilder
的用法示例。
在下文中一共展示了ODataConventionModelBuilder.Function方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetModel
private static IEdmModel GetModel()
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
EntitySetConfiguration<Trade> tradesConfiguration = builder.EntitySet<Trade>("Trades");
//Add bound function
var boundFunction = tradesConfiguration.EntityType.Collection.Function("GetTradingVolume");
boundFunction.Parameter<string>("productName");
boundFunction.Parameter<Country>("portingCountry");
boundFunction.Returns<long?>();
//Add bound function
boundFunction = tradesConfiguration.EntityType.Collection.Function("GetTopTrading");
boundFunction.Parameter<string>("productName");
boundFunction.ReturnsFromEntitySet<Trade>("Trades");
boundFunction.IsComposable = true;
//Add unbound function
var unboundFunction = builder.Function("GetTradeByCountry");
unboundFunction.Parameter<Country>("portingCountry");
unboundFunction.ReturnsCollectionFromEntitySet<Trade>("Trades");
builder.Namespace = typeof(Country).Namespace;
return builder.GetEdmModel();
}
示例2: GetModel
public static IEdmModel GetModel()
{
ODataModelBuilder builder = new ODataConventionModelBuilder();
builder.Namespace = "D";
builder.ContainerName = "Default";
EntitySetConfiguration<City> cities = builder.EntitySet<City>("City");
EntitySetConfiguration<Stadium> stadiums = builder.EntitySet<Stadium>("Stadium");
// Per Collection Stadium
FunctionConfiguration getStadiumsWithFunction = stadiums.EntityType.Collection.Function("GetStadiumsWithFunction");
getStadiumsWithFunction.ReturnsCollectionFromEntitySet<Stadium>("Stadium");
// Per Collection Stadium, returns single entity
FunctionConfiguration getStadiumsTest = stadiums.EntityType.Collection.Function("GetStadiumTest");
getStadiumsTest.Parameter<string>("test");
getStadiumsTest.Parameter<string>("name");
getStadiumsTest.ReturnsFromEntitySet<Stadium>("Stadium");
// Per Entity (Single key property) City
FunctionConfiguration getStadiumFromCityWithFunction = cities.EntityType.Function("GetStadiumsFromCityWithFunction");
getStadiumFromCityWithFunction.ReturnsCollectionFromEntitySet<Stadium>("Stadium");
// Per Entity composite key Stadium
FunctionConfiguration getCityFromStadiumWithFunction = stadiums.EntityType.Function("GetCityFromStadiumWithFunction");
getCityFromStadiumWithFunction.ReturnsFromEntitySet<City>("City");
// Global Function
builder.Function("GlobalFunction").ReturnsCollectionFromEntitySet<Stadium>("Stadium");
return builder.GetEdmModel();
}
示例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: ODataSwaggerConverterTest
public ODataSwaggerConverterTest()
{
var builder = new ODataConventionModelBuilder();
builder.EntitySet<Customer>("Customers");
builder.EntitySet<Order>("Orders");
builder.Function("UnboundFunction").Returns<string>().Parameter<int>("param");
builder.Action("UnboundAction").Parameter<double>("param");
builder.EntityType<Customer>().Function("BoundFunction").Returns<double>().Parameter<string>("name");
_model = builder.GetEdmModel();
}
示例5: StoreModel
static StoreModel()
{
var builder = new ODataConventionModelBuilder();
builder.Namespace = "Microsoft.Restier.WebApi.Test";
builder.EntitySet<Product>("Products");
builder.Function("GetBestProduct").ReturnsFromEntitySet<Product>("Products");
builder.Action("RemoveWorstProduct").ReturnsFromEntitySet<Product>("Products");
Model = (EdmModel)builder.GetEdmModel();
Product = (IEdmEntityType)Model.FindType("Microsoft.Restier.WebApi.Test.Product");
}
示例6: GetEdmModel
private static IEdmModel GetEdmModel()
{
var builder = new ODataConventionModelBuilder();
builder.EntitySet<Customer>("Customers");
builder.EntitySet<Order>("Orders");
builder.Function("UnboundFunction").Returns<string>().Parameter<int>("param");
builder.Action("UnboundAction").Parameter<double>("param");
builder.EntityType<Customer>().Function("BoundFunction").Returns<double>().Parameter<string>("name");
return builder.GetEdmModel();
}
示例7: GetEdmMode
private IEdmModel GetEdmMode()
{
ODataModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<OptionSet>("OptionSets");
builder.EntitySet<OptionSetEntity>("OptionSetEntities");
builder.EntitySet<GroupItemType>("GroupItemTypes");
builder.EntitySet<Group>("Groups");
builder.EntitySet<GroupItem>("GroupItems");
builder.Function("GetAllTables")
.ReturnsCollection<BaseTable>();
builder.Function("GetAllColumns")
.ReturnsCollection<BaseTable>()
.Parameter<string>("TableName");
return builder.GetEdmModel();
}
示例8: GetModel
private static IEdmModel GetModel()
{
ODataModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<DerivedTypeA>("SetA");
builder.EntitySet<DerivedTypeB>("SetB");
builder.EntityType<BaseType>(); // this line is necessary.
builder.Function("ReturnAll").ReturnsCollection<BaseType>();
return builder.GetEdmModel();
}
示例9: GetEdmModel
private static IEdmModel GetEdmModel()
{
var builder = new ODataConventionModelBuilder();
builder.EntitySet<Pin>("Pins");
builder.Function("Foo").Returns<int>();
builder.EntityType<Pin>().Collection.Function("Archived").ReturnsCollection<Pin>();
return builder.GetEdmModel();
}
示例10: GetEdmModel
private static IEdmModel GetEdmModel()
{
ODataModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Product2>("Products");
builder.Function("ProductsWithIds")
.ReturnsCollectionFromEntitySet<Product2>("Products")
.CollectionParameter<int>("Ids");
return builder.GetEdmModel();
}
示例11: GetEdmModel
private static IEdmModel GetEdmModel()
{
var builder = new ODataConventionModelBuilder();
builder.EntitySet<Customer>("Customers");
builder.EntitySet<Order>("Orders");
builder.Function("UnboundFunction").Returns<string>().Parameter<int>("param");
builder.Action("UnboundAction").Parameter<double>("param");
builder.EntityType<Customer>().Function("BoundFunction").Returns<double>().Parameter<string>("name");
builder.EntitySet<CompositeKeyItem>("CompositeKeyItems");
builder.EntityType<CompositeKeyItem>().HasKey(x => new { x.FirstKey, x.SecondKey });
return builder.GetEdmModel();
}
示例12: ConfigureSsisService
public static void ConfigureSsisService(this IAppBuilder app)
{
Debug.Assert(app != null);
//// build EDM model
var builder = new ODataConventionModelBuilder()
{
Namespace = typeof(SsisController).Namespace,
ContainerName = "DefaultContainer"
};
builder.ComplexType<JobParameter>();
builder.ComplexType<JobStatusResult>();
builder.EnumType<JobStatus>();
builder.EnumType<JobParameterType>();
{
var function = builder.Function("GetStatus");
function.Parameter<string>("name").OptionalParameter = false;
function.Returns<JobStatusResult>();
}
{
var action = builder.Action("Run");
action.Parameter<string>("name").OptionalParameter = false;
action.CollectionParameter<JobParameter>("parameters").OptionalParameter = false;
action.Returns<string>();
}
{
var action = builder.Action("Stop");
action.Parameter<string>("name").OptionalParameter = false;
action.Returns<string>();
}
var edmModel = builder.GetEdmModel();
//// configure web API
var config = new HttpConfiguration() { IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always };
config.MapODataServiceRoute("SsisService", "ssisservice", edmModel);
config.Services.Replace(typeof(IHttpControllerSelector), new ClientHttpControllerSelector(config, typeof(SsisServiceHelper)));
config.EnsureInitialized();
app.UseWebApi(config);
}
示例13: GetEdmModel
private static IEdmModel GetEdmModel(HttpConfiguration config)
{
ODataModelBuilder builder = new ODataConventionModelBuilder(config);
builder.EntitySet<Product>("Products");
var productType = builder.EntityType<Product>();
// Function bound to a collection
// Returns the most expensive product, a single entity
productType.Collection
.Function("MostExpensive")
.Returns<double>();
// Function bound to a collection
// 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");
// Unbound Function
builder.Function("GetSalesTaxRate")
.Returns<double>()
.Parameter<string>("state");
return builder.GetEdmModel();
}
示例14: GetModel
public static IEdmModel GetModel()
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
EntitySetConfiguration<Employee> employees = builder.EntitySet<Employee>("Employees");
EntityTypeConfiguration<Employee> employee = employees.EntityType;
// Action that adds a skill to the skill set.
ActionConfiguration actionConfiguration = employee.Action("AddAccessLevel");
actionConfiguration.Parameter<string>("AccessLevel");// Now action parameters does not support Enum type, so use string instead.
actionConfiguration.Returns<AccessLevel>();
// Function that tells whether an employee has the given AccessLevel
var functionConfiguration = builder.Function("HasAccessLevel");
functionConfiguration.Parameter<int>("ID");
functionConfiguration.Parameter<AccessLevel>("AccessLevel");
functionConfiguration.Returns<bool>();
builder.Namespace = typeof(Employee).Namespace;
return builder.GetEdmModel();
}
示例15: Configuration
public void Configuration(IAppBuilder builder)
{
var odataBuilder = new ODataConventionModelBuilder();
odataBuilder.EntitySet<Player>("Players");
var player = odataBuilder.EntityType<Player>();
//collection function
player.Collection.Function("TopPpg").ReturnsCollection<Player>();
//entity function
player.Function("PercentageOfAllGoals").Returns<double>();
//service function
var serviceFunc = odataBuilder.Function("TotalTeamPoints");
serviceFunc.Returns<int>().Parameter<string>("team");
serviceFunc.IncludeInServiceDocument = true;
var edm = odataBuilder.GetEdmModel();
var config = new HttpConfiguration();
config.MapODataServiceRoute("Default OData", "odata", edm);
builder.UseWebApi(config);
}