|
Structural Protocol enabling typed entity instances to be passed to
records.create() and records.update().
Implement this Protocol on any entity class (dataclass, Pydantic model,
hand-rolled) to enable it to be passed directly to CRUD operations without
specifying the table name or converting to dict manually.
Required class variables:
Required instance methods:
Example:
from dataclasses import dataclass
from PowerPlatform.Dataverse import DataverseModel
@dataclass
class Account:
__entity_logical_name__ = "account"
__entity_set_name__ = "accounts"
name: str = ""
telephone1: str = ""
def to_dict(self) -> dict:
return {"name": self.name, "telephone1": self.telephone1}
@classmethod
def from_dict(cls, data: dict) -> "Account":
return cls(
name=data.get("name", ""),
telephone1=data.get("telephone1", ""),
)
# isinstance() works today — Protocol is runtime_checkable:
assert isinstance(Account(), DataverseModel)
# Type your own helpers against the Protocol now:
def save(entity: DataverseModel) -> None:
data = entity.to_dict()
client.records.create(entity.__entity_logical_name__, data)
Note
Direct dispatch (client.records.create(entity) without a table name
or dict) is not yet supported and will be added in a future release.
|