在 Cofoundry 中使用 IDependableEntityDefinition 创建实体依赖
Creating entity dependencies using IDependableEntityDefinition in Cofoundry
是否有任何使用 IDependableEntityDefinition
的示例以及如何 link 两个实现 ICustomEntityDataModel
的自定义实体?
谢谢,
G
如果您 link 从自定义实体到非联合实体,您可能只会使用 IDependableEntityDefinition
,所以它有点高级用例并且不是没有记录。
如果你想 link 在自定义实体之间,你应该使用自定义实体数据注释,例如 [CustomEntity]
、[CustomEntityCollection]
或 [CustomEntityMultiTypeCollection]
,这里有一些关于这些的描述docs 中的属性。这些属性将自动为您跟踪依赖关系,并在关系不是可选的情况下防止删除依赖实体。
在下面的示例中,BreedId
是必需的依赖项,FurPatternId
是可选的:
public class CatDataModel : ICustomEntityDataModel
{
public string Description { get; set; }
[CustomEntity(BreedCustomEntityDefinition.DefinitionCode)]
public int BreedId { get; set; }
[CustomEntity(FurPatternCustomEntityDefinition.DefinitionCode)]
public int? FurPatternId { get; set; }
}
是否有任何使用 IDependableEntityDefinition
的示例以及如何 link 两个实现 ICustomEntityDataModel
的自定义实体?
谢谢, G
如果您 link 从自定义实体到非联合实体,您可能只会使用 IDependableEntityDefinition
,所以它有点高级用例并且不是没有记录。
如果你想 link 在自定义实体之间,你应该使用自定义实体数据注释,例如 [CustomEntity]
、[CustomEntityCollection]
或 [CustomEntityMultiTypeCollection]
,这里有一些关于这些的描述docs 中的属性。这些属性将自动为您跟踪依赖关系,并在关系不是可选的情况下防止删除依赖实体。
在下面的示例中,BreedId
是必需的依赖项,FurPatternId
是可选的:
public class CatDataModel : ICustomEntityDataModel
{
public string Description { get; set; }
[CustomEntity(BreedCustomEntityDefinition.DefinitionCode)]
public int BreedId { get; set; }
[CustomEntity(FurPatternCustomEntityDefinition.DefinitionCode)]
public int? FurPatternId { get; set; }
}