Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is meaning of <FunctionImport> in OData Metadata?

Tags:

odata

After I went through OData doc, I still do not understand the meaning of <FunctionImport>.

  1. What is that used for? Some one said that "Function imports are used to perform custom operations on a JPA entity in addition to CRUD operations. For example, consider a scenario where you would like to check the availability of an item to promise on the sales order line items. ATP check is a custom operation that can be exposed as a function import in the schema of OData service."

But I think above requirement can be achieved by general <Function> also, right?

  1. What is the difference between <FunctionImport> and <Function> exactly?

I do appreciate anyone's help! Thanks

like image 898
Xianyi Ye Avatar asked Dec 14 '22 16:12

Xianyi Ye


1 Answers

There are three types of functions in OData:

  1. Functions that are bound to something (e.g. an entity). Example would be GET http://host/service/Products(1)/Namespace.GetCategories() such function is defined in the metadata using the <function> element and with its isBound attribute set to true.
  2. Unbound functions. They are usually used in queries. E.g. GET http://host/service/Products?$filter(Name eq Namespace.GetTheLongestProductName()) such function is defined in the metadata using the <function> element with its isBound attribute set to false
  3. Function imports. They are the functions that can be invoked at the service root. E.g. GET http://host/service/GetMostExpensiveProduct() Their concept is a little bit similar as the concept of static functions in program languages, and they are defined in metadata using the <functionimport> element.

Similar distinguishing applies to <action> and <actionimport> as well.

like image 187
Yi Ding - MSFT Avatar answered Mar 16 '23 20:03

Yi Ding - MSFT