Edit

Use OData to return and obtain a service metadata document

The Entity Data Model (EDM) is a specification for defining the data that is used by applications that are built on the Entity Framework. EDMX is an XML-based file format that is the packaging format for the service metadata of a data service. When you interact with an OData service that is published from Business Central, you can request EDM-based proxies, Then, use tools such as LINQ to create data access logic. LINQ is a programming model that developers can use to query data from various data sources, including OData. Learn more in LINQ (Language-Integrated Query).

The Business Central implementation of EDM follows the .NET 4.0 WCF Data Service Framework implementation.

The following guidelines are implemented for EDM.

  • Primary key fields in tables are automatically defined as properties in the service metadata document even if they aren't exposed on a page as controls.

  • Business Central field names are mapped to EDMX property names by applying the following transformations:

    • Spaces are replaced with underscores (_)
    • Dots (.) are removed (example: No.No)
    • Parentheses are removed (example: Balance (LCY)Balance_LCY)
    • Slashes (/) are replaced with underscores (example: Country/RegionCountry_Region)
    • Apostrophes (') are encoded as _x0027_ (example: Don'tDon_x0027_t)
    • Percent signs (%) are replaced with Percent (example: Profit %Profit_Percent)

Obtain a service metadata (EDMX) document

  1. You can obtain service metadata documents for either page or query web services. This example uses a page web service. Register and publish a page web service by using the Business Central Web client. See Publishing a Web Service..

  2. Start a supported web browser, such as Microsoft Edge. In the Address field, enter a URI in this format:

    https://<Server>:<WebServicePort>/<ServerInstance>/ODataV4/$metadata  
    

    If Business Central Server is running on the local computer and is using the default Business Central Server instance and OData port, then the address is:

    https://localhost:7048/<server instance>/ODataV4/$metadata  
    

    The browser should now show the complete metadata for the page web service that you published. The beginning of this document looks like this:

    <edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
     <edmx:DataServices>
      <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="NAV">
       <EntityType Name="Media">
        <Key>
          <PropertyRef Name="ID"/>
        </Key>
        <Property Name="ID" Type="Edm.Guid" Nullable="false">
          <Annotation Term="NAV.LabelId" String="ID"/>
          <Annotation Term="NAV.NavType">
            <EnumMember>NAV.NavType/Guid</EnumMember>
          </Annotation>
          <Annotation Term="NAV.AllowEditOnCreate" Bool="true"/>
        </Property>
        ...
    

OData Web Services