microsoft / CDM

The Common Data Model (CDM) is a standard and extensible collection of schemas (entities, attributes, relationships) that represents business concepts and activities with well-defined semantics, to facilitate data interoperability. Examples of entities include: Account, Contact, Lead, Opportunity, Product, etc.
https://powerplatform.microsoft.com/en-us/common-data-model/
Creative Commons Attribution 4.0 International
1.67k stars 526 forks source link

How to create relationship between entities using Python ? #337

Closed deepspraj closed 1 year ago

deepspraj commented 1 year ago

Opening this issue as I am unable to re-open issue no 336. Reference to issue no 336.

@llawwaii Thank you for guiding us. As stated by you the sample no 6 is supported by C# and Java. Can you please show me the path where I can get to know how to generate relationships between entities using Python?

When we create relationships in manifest file is it necessary to mention primary and foreign key attribute in entity.cdm.json file ? And when we try to generate relationship between entities using C# code in manifest file and add to cdm container, this code doesn't create entity.cdm.json file respectively for entities in same container but updates the manifest file with partition status of each entity.

victor-gutemberg commented 1 year ago

Hello @deepspraj,

our APIs are the same across all the languages we support. You just need to convert the syntax and the code should work just fine.

The best practice to create relationships in a manifest is to mark the corresponding attributes on the entity.cdm.json files, add a reference to those entities on a manifest and call the create_resolved_manifest_async method. That will generate a manifest containing all relationships found from looking at foreign key attributes.

The sample 2 shows exactly what I described above. The only difference is that it's using a deprecated feature called "ResolutionGuidance", I'll include some links below on how to use the new feature called "Projections" to achieve the same result.

For reference about how to mark attributes as foreign keys take a look at the links mentioned on the previous issue: https://learn.microsoft.com/en-us/common-data-model/sdk/projections/replaceasforeignkey https://github.com/microsoft/CDM/tree/master/samples/8-logical-manipulation-using-projections

The code you linked above is not maintained by us; this repo is only for the CDM SDK. Please contact the CDM Spark Connector team about question related to that piece of code.