コード例 #1
0
        public static Dictionary <string, string> GetLookupPropertiesMappingDictionary(this Edmx edmx, Type entityClrType)
        {
            string entityName = entityClrType.Name;
            Dictionary <string, string> mappingDictionary = new Dictionary <string, string>();

            foreach (NavigationProperty navigationProperty in edmx.GetLookupProperties(entityClrType))
            {
                string relationship = GetAdjustedText(navigationProperty.Relationship);

                string fromRole = navigationProperty.FromRole;
                string toRole   = navigationProperty.ToRole;

                LinqToEdmx.Model.Conceptual.Association association = edmx.GetConceptualAssociation(relationship);

                LinqToEdmx.Model.Conceptual.AssociationEnd fromAssociation = edmx.GetConceptualAssociationEnd(relationship, fromRole);
                LinqToEdmx.Model.Conceptual.AssociationEnd toAssociation   = edmx.GetConceptualAssociationEnd(relationship, toRole);

                AssociationSetMapping entityTypesMappingAssociation = edmx.GetMappingAssociationSet(entityName, relationship);
                foreach (EndProperty endProperty in entityTypesMappingAssociation.EndProperties)
                {
                    if (endProperty.Name == toRole)
                    {
                        string columnName = endProperty.ScalarProperties[0].ColumnName;
                        mappingDictionary.Add(navigationProperty.Name, columnName);
                    }
                }
            }

            return(mappingDictionary);
        }
コード例 #2
0
        public static EndProperty GetParentChildRelationEndProperty(this Edmx edmx, string parentEntityName, string childPropertyName)
        {
            NavigationProperty navigationProperty = edmx.GetNavigationProperty(parentEntityName, childPropertyName);
            string             relationship       = GetAdjustedText(navigationProperty.Relationship);

            string fromRole = navigationProperty.FromRole;
            string toRole   = navigationProperty.ToRole;

            LinqToEdmx.Model.Conceptual.Association association = edmx.GetConceptualAssociation(relationship);

            LinqToEdmx.Model.Conceptual.AssociationEnd fromAssociation = edmx.GetConceptualAssociationEnd(relationship, fromRole);
            LinqToEdmx.Model.Conceptual.AssociationEnd toAssociation   = edmx.GetConceptualAssociationEnd(relationship, toRole);

            string childEntityName = GetAdjustedText(toAssociation.Type);
            AssociationSetMapping entityTypesMappingAssociation = edmx.GetMappingAssociationSet(childEntityName, relationship);

            return(entityTypesMappingAssociation.EndProperties.Where(e => e.Name == fromRole).Single());
        }
コード例 #3
0
        private AssociationEnd CreateConceptualAssociationEnd(IEntity entity, string role, LinqToEdmx.Model.Conceptual.Association assocication, bool isCascadeDelete)
        {
            //  <End Role="Category" Type="PetShopModel1.Category" Multiplicity="1">
            //     <OnDelete Action="Cascade" />
            //  </End>
            //  <End Role="Product" Type="PetShopModel1.Product" Multiplicity="*" />
            var end = new AssociationEnd()
            {
                Role = role,
                Type = String.Concat(ConceptualSchema.Namespace, ".", ResolveEntityMappedName(entity.EntityKey(), entity.Name))
            };

            if (isCascadeDelete)
            {
                end.OnDelete.Add(new OnAction() { Action = EdmxConstants.OnDeleteActionCascade });
            }

            assocication.Ends.Add(end);

            return end;
        }
コード例 #4
0
 private static void UpdateConceptualAssociationEndMultiplicity(IAssociation association, AssociationEnd principalEnd, AssociationEnd dependentEnd)
 {
     switch (association.AssociationType)
     {
         case AssociationType.OneToMany:
             principalEnd.Multiplicity = MultiplicityConstants.One;
             dependentEnd.Multiplicity = MultiplicityConstants.Many;
             break;
         case AssociationType.OneToOne:
             principalEnd.Multiplicity = MultiplicityConstants.One;
             dependentEnd.Multiplicity = MultiplicityConstants.One;
             break;
         case AssociationType.OneToZeroOrOne:
             principalEnd.Multiplicity = MultiplicityConstants.One;
             dependentEnd.Multiplicity = MultiplicityConstants.ZeroToOne;
             break;
         case AssociationType.ZeroOrOneToMany:
         case AssociationType.ManyToZeroOrOne:
             principalEnd.Multiplicity = MultiplicityConstants.ZeroToOne;
             dependentEnd.Multiplicity = MultiplicityConstants.Many;
             break;
         case AssociationType.ManyToMany:
             principalEnd.Multiplicity = MultiplicityConstants.Many;
             dependentEnd.Multiplicity = MultiplicityConstants.Many;
             break;
         default:
             principalEnd.Multiplicity = MultiplicityConstants.One;
             dependentEnd.Multiplicity = MultiplicityConstants.Many;
             break;
     }
 }