Beispiel #1
0
            public override bool Equals(object other)
            {
                AssociationKey that = other as AssociationKey;

                if (that == null)
                {
                    return(false);
                }

                return(that.table.Equals(table) && CollectionHelper.SequenceEquals <string>(columns, that.columns));
            }
Beispiel #2
0
        /// <summary>
        /// Used to detect circularities in the joined graph, note that
        /// this method is side-effecty
        /// </summary>
        protected virtual bool IsDuplicateAssociation(string foreignKeyTable, string[] foreignKeyColumns)
        {
            AssociationKey associationKey = new AssociationKey(foreignKeyColumns, foreignKeyTable);

            return(!visitedAssociationKeys.Add(associationKey));
        }
Beispiel #3
0
        private void CreateAssociation(Table foreignTable, TableKeySchema tableKeySchema)
        {
            if (Settings.IsIgnored(tableKeySchema.PrimaryKeyTable.FullName))
            {
                Debug.WriteLine("Skipping Association because one of the tables is skipped: " + tableKeySchema.Name);
                Trace.WriteLine("Skipping Association because one of the tables is skipped: " + tableKeySchema.Name);
                return;
            }

            // skip unsupported type
            if (tableKeySchema.ForeignKeyMemberColumns.Any(c => Settings.IsUnsupportedDbType(c)) ||
                tableKeySchema.PrimaryKeyMemberColumns.Any(c => Settings.IsUnsupportedDbType(c)))
            {
                Debug.WriteLine("Skipping Association because one of the associated columns is an unsupported db type: " + tableKeySchema.Name);
                Trace.WriteLine("Skipping Association because one of the associated columns is an unsupported db type: " + tableKeySchema.Name);
                return;
            }

            Table primaryTable = GetTable(tableKeySchema.PrimaryKeyTable, false);

            string primaryClass = primaryTable.Type.Name;
            string foreignClass = foreignTable.Type.Name;

            string name = string.Format("{0}_{1}", primaryClass, foreignClass);

            name = MakeUnique(AssociationNames, name);

            string foreignMembers = GetKeyMembers(foreignTable,
                                                  tableKeySchema.ForeignKeyMemberColumns, tableKeySchema.Name);

            string primaryMembers = GetKeyMembers(primaryTable,
                                                  tableKeySchema.PrimaryKeyMemberColumns, tableKeySchema.Name);

            AssociationKey key   = AssociationKey.CreateForeignKey(name);
            bool           isNew = !foreignTable.Type.Associations.Contains(key);

            Association foreignAssociation;

            if (isNew)
            {
                foreignAssociation = new Association(name);
            }
            else
            {
                foreignAssociation = foreignTable.Type.Associations[key];
            }

            foreignAssociation.IsForeignKey = true;
            foreignAssociation.ThisKey      = foreignMembers;
            foreignAssociation.OtherKey     = primaryMembers;
            foreignAssociation.Type         = primaryClass;

            string prefix = GetMemberPrefix(foreignAssociation, primaryClass, foreignClass);

            if (isNew)
            {
                foreignAssociation.Member  = ToPropertyName(foreignTable.Type.Name, prefix + primaryClass);
                foreignAssociation.Storage = CommonUtility.GetFieldName(foreignAssociation.Member);
                foreignTable.Type.Associations.Add(foreignAssociation);
            }
            else
            {
                PropertyNames[foreignTable.Type.Name].Add(foreignAssociation.Member);
            }

            // add reverse association
            key   = AssociationKey.CreatePrimaryKey(name);
            isNew = !primaryTable.Type.Associations.Contains(key);

            Association primaryAssociation;

            if (isNew)
            {
                primaryAssociation = new Association(name);
            }
            else
            {
                primaryAssociation = primaryTable.Type.Associations[key];
            }

            primaryAssociation.IsForeignKey = false;
            primaryAssociation.ThisKey      = foreignAssociation.OtherKey;
            primaryAssociation.OtherKey     = foreignAssociation.ThisKey;
            primaryAssociation.Type         = foreignClass;

            bool isOneToOne = IsOneToOne(tableKeySchema, foreignAssociation);

            if (primaryAssociation.Cardinality == null && isOneToOne)
            {
                primaryAssociation.Cardinality = Cardinality.One;
            }

            if (isNew)
            {
                string propertyName = prefix + foreignClass;
                if (!isOneToOne)
                {
                    if (settings.AssociationNaming == AssociationNamingEnum.ListSuffix)
                    {
                        propertyName += "List";
                    }
                    else if (settings.AssociationNaming == AssociationNamingEnum.Plural)
                    {
                        propertyName = StringUtil.ToPlural(propertyName);
                    }
                }

                primaryAssociation.Member  = ToPropertyName(primaryTable.Type.Name, propertyName);
                primaryAssociation.Storage = CommonUtility.GetFieldName(primaryAssociation.Member);
                primaryTable.Type.Associations.Add(primaryAssociation);
            }
            else
            {
                PropertyNames[primaryTable.Type.Name].Add(primaryAssociation.Member);
            }

            if (IsTableKeySchemaCascadeDelete(tableKeySchema))
            {
                foreignAssociation.DeleteRule = "CASCADE";
            }

            if (settings.IncludeDeleteOnNull || foreignTable.Type.IsManyToMany())
            {
                if (!foreignAssociation.DeleteOnNull.HasValue && IsTableDeleteOnNull(tableKeySchema))
                {
                    foreignAssociation.DeleteOnNull = true;
                }
            }
            else
            {
                foreignAssociation.DeleteOnNull = null;
            }

            foreignAssociation.IsProcessed = true;
            primaryAssociation.IsProcessed = true;
        }
 public static extern HResult AssocQueryKeyW(
     AssociationFlags flags,
     AssociationKey key,
     string pszAssoc,
     string pszExtra,
     out RegistryKeyHandle phkeyOut);
Beispiel #5
0
 public static RegistryKeyHandle AssocQueryKey(AssociationFlags flags, AssociationKey key, string association, string extraInfo)
 {
     Imports.AssocQueryKeyW(flags, key, association, extraInfo, out RegistryKeyHandle handle)
     .ThrowIfFailed();
     return(handle);
 }