on 2020 Sep 02 9:28 AM
Hi,
I am trying to write a cds projection using reference as blog-example and documentation. i am not able to write "as projection" statement with distinct keyword. (or alternatively cds variant "as select" with key defined).
The below code works fine, but i am expecting distinct values in result.
using {aatp.risk as riskSchema} from '../db/risk-schema';
@path:'dashboard' service DashboardService
{
entity RiskInputData as projection on riskSchema.riskInputData;
entity Plant as projection on RiskInputData { key plant};
entity MrpController as projection on RiskInputData { key plant, key mrpController};
}
Alternatively, if ii write the same with "as select" statements below, i am getting a OData error >>
using {aatp.risk as riskSchema} from '../db/risk-schema';
@path:'dashboard' service DashboardService
{
entity RiskInputData as projection on riskSchema.riskInputData;
entity Plant as select distinct plant from RiskInputData;
entity MrpController as select distinct a.plant, a.mrpController from RiskInputData as a;
}
[0] srv.json:931: Error: Entity "DashboardService.MrpController" does not
have a key: ODATA entities must have a key
[0] srv.json:970: Error: Entity "DashboardService.Plant" does not have a key: ODATA entities must have a key
Regards
Request clarification before answering.
With SELECT, you were on the right track, but please also specify the keys there, too.
You might also want to use the CDS-like syntax (FROM first, which is better for code completion)
using {aatp.risk as riskSchema} from '../db/risk-schema';
@path:'dashboard' service DashboardService
{
entity RiskInputData as select from riskSchema.riskInputData;
entity Plant as select from RiskInputData distinct { key plant};
entity MrpController as select from RiskInputData distinct { key plant, key mrpController};
}
(OK, we should probably allow the DISTINCT also directly after the SELECT…, but this is how it works now and will continue to work.)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
73 | |
30 | |
8 | |
8 | |
7 | |
6 | |
6 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.