一键导入
odata-data-sharing
Share data between Mendix apps via OData services using view entities, published services, external entities, and OData clients
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Share data between Mendix apps via OData services using view entities, published services, external entities, and OData clients
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Mendix MDL authoring, project navigation, and Docker app lifecycle — entities, microflows, pages, security, navigation, OQL, REST, testing, linting, and migration. Load when working in any Mendix codebase.
MDL Agent Documents — CREATE MODEL, CREATE KNOWLEDGE BASE, CREATE CONSUMED MCP SERVICE, CREATE AGENT syntax and calling agents from microflows
ALTER PAGE / ALTER SNIPPET — SET, INSERT, DROP, REPLACE widget operations on existing pages and snippets
Migration Assessment — structured investigation of non-Mendix projects for migration planning across technology stack, data model, business logic, UI, integrations, and security
Assess Mendix Project Quality — automated linting, catalog queries, naming conventions, security, maintainability, performance, and architecture review with scored report
Browse Integration Services and Contracts — SHOW/DESCRIBE OData, REST, business event, and database connection services; query MDL CATALOG integration tables; import external entities
| name | odata-data-sharing |
| description | Share data between Mendix apps via OData services using view entities, published services, external entities, and OData clients |
| compatibility | opencode |
<metadata_url_formats>
CREATE ODATA CLIENT supports three formats for the MetadataUrl parameter:
| Format | Example | Stored In Model |
|---|---|---|
| HTTP(S) URL | https://api.example.com/odata/v4/$metadata | Unchanged |
| Absolute file:// URI | file:///Users/team/contracts/service.xml | Unchanged |
| Relative path | ./metadata/service.xml or metadata/service.xml | Normalized to absolute file:// |
Path Normalization:
file:// URLs in the Mendix model-p flag or REPL): relative paths resolved against the .mpr file's directoryUse Cases for Local Metadata:
<service_url_must_be_constant>
IMPORTANT: The ServiceUrl parameter must always be a constant reference (prefixed with @).
-- Correct
CREATE CONSTANT ProductClient.ProductDataApiLocation
TYPE String
DEFAULT 'http://localhost:8080/odata/productdataapi/v1/';
CREATE ODATA CLIENT ProductClient.ProductDataApiClient (
ODataVersion: OData4,
MetadataUrl: 'https://api.example.com/$metadata',
ServiceUrl: '@ProductClient.ProductDataApiLocation' -- ✅ Constant reference
);
-- Incorrect
CREATE ODATA CLIENT ProductClient.ProductDataApiClient (
ODataVersion: OData4,
MetadataUrl: 'https://api.example.com/$metadata',
ServiceUrl: 'https://api.example.com/odata' -- ❌ Direct URL not allowed
);
</service_url_must_be_constant>
<architecture_overview> OData data sharing follows a producer/consumer pattern with three layers:
┌─────────────────────────────────────────────┐
│ PRODUCER APP │
│ │
│ persistent entities ──▶ view entities │
│ (Shop.Customer, (Api.CustomerVE) │
│ Shop.Address) │
│ ▼ │
│ odata service │
│ (Api.CustomerApi) │
└──────────────────────┬──────────────────────┘
│ HTTP/OData4
┌──────────────────────▼──────────────────────┐
│ CONSUMER APP │
│ │
│ odata client │
│ (Client.CustomerApiClient) │
│ ▼ │
│ external entities │
│ (Client.CustomersEE) │
└─────────────────────────────────────────────┘
Publishing persistent entities directly exposes your internal schema. View entities solve this:
<read_only_api_steps>
create module ProductApi;
create module role ProductApi.ApiUser
description 'Role for OData API access';
/**
* Flattened product with current active price.
*/
create view entity ProductApi.ProductWithPriceVE (
ProductId: integer,
Name: string,
description: string,
PriceInEuro: decimal
) as (
select p.ID as ProdId
, p.ProductId as ProductId
, p.Name as Name
, p.Description as description
, ( select pr.PriceInEuro
from Shop.Price as pr
where pr.StartDate <= '[%BeginOfTomorrow%]'
and pr/Shop.Price_Product = p.ID
order by pr.StartDate desc
limit 1
) as PriceInEuro
from Shop.Product as p
where p.IsActive
);
grant ProductApi.ApiUser on ProductApi.ProductWithPriceVE
(read *, write *);
create odata service ProductApi.ProductDataApi (
path: 'odata/productdataapi/v1/',
version: '1.0.0',
ODataVersion: OData4,
namespace: 'DefaultNamespace',
ServiceName: 'ProductDataApi',
Summary: 'Product and customer data API',
PublishAssociations: No
)
authentication basic
{
publish entity ProductApi.ProductWithPriceVE as 'Product' (
ReadMode: ReadFromDatabase,
InsertMode: NotSupported,
UpdateMode: NotSupported,
DeleteMode: NotSupported
)
expose (
ProductId as 'ProductId' (Filterable, Sortable, key),
Name as 'Name' (Filterable, Sortable),
description as 'Description' (Filterable, Sortable),
PriceInEuro as 'PriceInEuro' (Filterable, Sortable)
);
};
grant access on odata service ProductApi.ProductDataApi
to ProductApi.ApiUser;
create module ProductClient;
create module role ProductClient.User;
create constant ProductClient.ProductDataApiLocation
type string
default 'http://localhost:8080/odata/productdataapi/v1/';
create odata client ProductClient.ProductDataApiClient (
ODataVersion: OData4,
MetadataUrl: 'http://localhost:8080/odata/productdataapi/v1/$metadata',
timeout: 300,
ServiceUrl: '@ProductClient.ProductDataApiLocation',
UseAuthentication: Yes,
HttpUsername: 'MxAdmin',
HttpPassword: '1'
);
-- External entities (mapped from published service)
create external entity ProductClient.ProductsEE
from odata client ProductClient.ProductDataApiClient
(
EntitySet: 'Product',
RemoteName: 'Product',
Countable: Yes
)
(
ProductId: long,
Name: string,
description: string,
PriceInEuro: decimal
);
grant ProductClient.User on ProductClient.ProductsEE (read *);
Bulk alternative:
-- All entities from the service
create external entities from ProductClient.ProductDataApiClient;
-- Or specific ones only
create external entities from ProductClient.ProductDataApiClient
entities (Product, CustomerAddress);
-- Idempotent re-import
create or modify external entities from ProductClient.ProductDataApiClient;
</read_only_api_steps>
<read_write_api> For write operations, the OData service delegates to microflows that map between the view entity and the underlying persistent entities.
create microflow ProductApi.InsertProductWithPriceVE (
$ProductWithPriceVE: ProductApi.ProductWithPriceVE,
$HttpRequest: System.HttpRequest
)
begin
$Product = create Shop.Product (
Name = $ProductWithPriceVE/Name,
description = $ProductWithPriceVE/description,
IsActive = true
);
commit $Product;
$Price = create Shop.Price (
PriceInEuro = $ProductWithPriceVE/PriceInEuro,
StartDate = '[%CurrentDateTime%]'
);
change $Price (Shop.Price_Product = $Product);
commit $Price;
end;
grant execute on microflow ProductApi.InsertProductWithPriceVE
to ProductApi.ApiUser;
publish entity ProductApi.ProductWithPriceVE as 'Product' (
ReadMode: ReadFromDatabase,
InsertMode: microflow ProductApi.InsertProductWithPriceVE,
UpdateMode: microflow ProductApi.UpdateProductWithPriceVE,
DeleteMode: microflow ProductApi.DeleteProductWithPriceVE
)
expose (...);
grant ProductClient.User on ProductClient.ProductsEE
(create, delete, read *, write *);
</read_write_api>
<exploration_commands>
-- List all published and consumed services
show odata services;
show odata clients;
-- Inspect a specific service
describe odata service ShopViews.ShopViewsApi;
describe odata client ShopViewsClient.ShopViewsApiClient;
-- See external entities and view entities
show entities in ShopViewsClient;
show external entities;
show external actions;
-- Browse available assets from cached $metadata contract
show contract entities from ShopViewsClient.ShopViewsApiClient;
show contract actions from ShopViewsClient.ShopViewsApiClient;
describe contract entity ShopViewsClient.ShopViewsApiClient.Product;
describe contract entity ShopViewsClient.ShopViewsApiClient.Product format mdl;
-- Check security setup
show access on odata service ShopViews.ShopViewsApi;
show module roles in ShopViews;
</exploration_commands>
<module_organization>
| Module | Purpose | Contains |
|---|---|---|
Shop | Core domain | Persistent entities, business logic |
ShopApi or ShopViews | API layer (producer) | View entities, OData service, CUD microflows |
ShopClient or ShopViewsClient | API consumer | OData client, external entities, client constants |
| </module_organization> |
Before consuming:
MetadataUrl points to HTTP(S) URL, absolute file://, or relative pathServiceUrl: '@Module.Constant' for runtime endpoint<output_rules>Output MDL code only in code blocks. Keep explanations concise.</output_rules>