Esempio n. 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);
        }