80 likes | 251 Views
Association Simplification. Issues with Associations. Defining Associations (and association sets) in order to represent links is cumbersome Associations are bi-directional Difficult to do Composition Want to model root as a single entity. Associations Today. < EntityType Name = " Genre " >
E N D
Issues with Associations • Defining Associations (and association sets) in order to represent links is cumbersome • Associations are bi-directional • Difficult to do Composition • Want to model root as a single entity
Associations Today <EntityTypeName="Genre"> <Key> <PropertyRefName="Name"/> </Key> <PropertyName="Name"Nullable="false"Type="Edm.String"/> <NavigationPropertyName="Titles"Relationship="Netflix.Catalog.v2.Genre_Titles" ToRole="Genre_Titles_Target"FromRole="Genre_Titles_Source" /> </EntityType> <EntityTypeName="Film"> <Key> <PropertyRefName="Name"/> </Key> <PropertyName="Name"Nullable="false"Type="Edm.String"/> <NavigationPropertyName="Genre"Relationship="Netflix.Catalog.v2.Genre_Titles" ToRole="Genre_Titles_Source"FromRole="Genre_Titles_Target" /> </EntityType> <AssociationName="Genre_Titles"> <EndType="Netflix.Catalog.v2.Genre"Multiplicity="1"Role="Genre_Titles_Source"/> <EndType="Netflix.Catalog.v2.Title"Multiplicity="*"Role="Genre_Titles_Target"/> </Association> <EntityContainerName="NetflixCatalog"> <EntitySetName="Genres"EntityType="Netflix.Catalog.v2.Genre"/> <EntitySetName="Titles"EntityType="Netflix.Catalog.v2.Film"/> <AssociationSetName="Title_Discs"Association="Netflix.Catalog.v2.Title_Discs"> <EndRole="Title_Discs_Source"EntitySet="Titles"/> <EndRole="Title_Discs_Target"EntitySet="Genres"/> </AssociationSet> </EntityContainer>
How Associations Could Look <EntityTypeName="Genre"> <Key> <PropertyRefName="Name"/> </Key> <PropertyName="Name"Nullable="false"Type="Edm.String"/> <NavigationPropertyName="Titles"Type="Collection(Netflix.Catalog.V2.Title)" Partner="Genre"/> </EntityType> <EntityTypeName="Film"> <Key> <PropertyRefName="Name"/> </Key> <PropertyName="Name"Nullable="false"Type="Edm.String"/> <NavigationPropertyName="Genre"Type"Netflix.Catalog.v2.Genre"nullable="false" Partner="Titles"/> </EntityType> <EntityContainerName="NetflixCatalog"> <EntitySetName="Genres"EntityType="Netflix.Catalog.v2.Genre"> <NavigationPropertyBindingPath="Titles"EntitySet="Titles"/> </EntitySet> <EntitySetName="Titles"EntityType="Netflix.Catalog.v2.Film"> <NavigationPropertyBindingPath="Genre"EntitySet="Genres"/> </EntitySet> </EntityContainer>
Root Entity • Often you have a single root element, with properties, with relationships to other EntitySets • Model as a "Named Entity" rooted at the entity container: <EntityContainerName="Sales"> <EntityName="Consoto"Type="Enterprise.Company" /> </EntityContainer>
Changes • Support specifying Type, Nullability, Partner in Navigation Property • Partner may be optional • Specify NavigationPropertyBinding in EntitySet • Binding may be optional • Addition of "Top Level Entity" • Supports root entity
Benefits • Simpler to read • Information is localized where you expect to find it • Enables one-way relationships • Makes it easier to support Composition • Doesn't change OData semantics, behavior, etc.
Discussion • Instead of root element make the EntityContainer an entity type