Skip to content

Map .net method to bound function

Maxim edited this page Nov 14, 2019 · 5 revisions

Data context method mapped to bound function must decorate OeBoundFunctionAttribute. First method parameter must be OeBoundFunctionParameter type. Supported invoke bound function without advertised namespace.

[Db.OeBoundFunction(CollectionFunctionName = "BoundFunctionCollection", SingleFunctionName = "BoundFunctionSingle")]
public static IEnumerable<Order> BoundFunction(Db.OeBoundFunctionParameter<Customer, Order> boundParameter, IEnumerable<String> orderNames)
{
    //create DbContext
    OrderContext orderContext = boundParameter.CreateDataContext<OrderContext>();

    //apply query part before bound function - Customers/$filter(Sex eq 'Female')
    IQueryable<Customer> customers = boundParameter.ApplyFilter(orderContext.Customers, orderContext);
    IQueryable<Order> orders = customers.SelectMany(c => c.Orders).Where(o => orderNames.Contains(o.Name));

    //apply query part after bound function - $expand=Customer,Items&$select=Name
    IQueryable result = boundParameter.ApplySelect(orders, orderContext);
    List<Order> orderList = boundParameter.Materialize(result).ToListAsync().GetAwaiter().GetResult();

    boundParameter.CloseDataContext(orderContext);
    return orderList;
}

Invoke bound collection of entities without advertised namespace

Customers/$filter(Sex eq 'Female')/BoundFunctionCollection(orderNames=['Order 1','Order 2'])?$expand=Customer,Items&$select=Name

Invoke bound to entity

Customers('RU',1)/OdataToEntity.Test.Model.BoundFunctionSingle(orderNames=['Order 1','Order 2'])?$expand=Customer,Items&$select=Name