Ejemplo n.º 1
0
 public void AssignFrom(AssociationItem other)
 {
     this.Id = other.Id;
     this.ForeignKeyColumn          = other.ForeignKeyColumn;
     this.AuxiliaryForeignKeyColumn = other.AuxiliaryForeignKeyColumn;
     this.AssocationType            = other.AssocationType;
     this.OwnerSetting.AssignFrom(other.OwnerSetting);
     this.TargetSetting.AssignFrom(other.TargetSetting);
 }
Ejemplo n.º 2
0
        public AssociationItem Clone()
        {
            AssociationItem cloned = new AssociationItem(this.ForeignKeyColumn, this.AuxiliaryForeignKeyColumn, this.AssocationType);

            cloned.Id            = this.Id;
            cloned.OwnerSetting  = this.OwnerSetting.Clone();
            cloned.TargetSetting = this.TargetSetting.Clone();

            return(cloned);
        }
Ejemplo n.º 3
0
        public bool EqualsToSpecial(AssociationItem other)
        {
            var ownerData  = GetInfo(true);
            var targetData = GetInfo(false);

            var otherOwnerData  = other.GetInfo(true);
            var otherTargetData = other.GetInfo(false);

            return(IsEqual(otherOwnerData, ownerData) || IsEqual(otherOwnerData, targetData) ||
                   IsEqual(otherTargetData, ownerData) || IsEqual(otherTargetData, targetData));
        }
Ejemplo n.º 4
0
        private void ScanTables(IEnumerable <Table> tables)
        {
            foreach (var table in tables)
            {
                List <AssociationItem> items = new List <AssociationItem>();
                var isAuxiliary = DetectTableIsAuxiliary(table);

                if (!auxiliaryTables.ContainsKey(table))
                {
                    auxiliaryTables.Add(table, isAuxiliary);
                }
                else if (!auxiliaryTables[table].HasValue)
                {
                    auxiliaryTables[table] = isAuxiliary;
                }

                if (isAuxiliary)
                {
                    ForeignKeyColumn foreignKeyColumn    = table.ForeignKeys[0].Columns[0];
                    ForeignKeyColumn auxForeignKeyColumn = table.ForeignKeys[1].Columns[0];

                    var associationItem = new AssociationItem(foreignKeyColumn, auxForeignKeyColumn, AssocationType.OneToMany);

                    var genResult = GenerateAssociationPropertyNames(AssocationType.OneToMany, associationItem);
                    associationItem.OwnerSetting.PropertyName  = genResult.Item1;
                    associationItem.OwnerSetting.PropertyType  = genResult.Item2;
                    associationItem.TargetSetting.PropertyName = genResult.Item3;
                    associationItem.TargetSetting.PropertyType = genResult.Item4;

                    //addItemFunc(allAssociationItems, items, associationItem);
                }
                else
                {
                    foreach (var foreignKey in table.ForeignKeys)
                    {
                        var associationItem = new AssociationItem(foreignKey.Columns[0], AssocationType.OneToOne);
                        var genResult       = GenerateAssociationPropertyNames(AssocationType.OneToOne, associationItem);
                        associationItem.OwnerSetting.PropertyName  = genResult.Item1;
                        associationItem.OwnerSetting.PropertyType  = genResult.Item2;
                        associationItem.TargetSetting.PropertyName = genResult.Item3;
                        associationItem.TargetSetting.PropertyType = genResult.Item4;

                        //addItemFunc(allAssociationItems, items, associationItem);
                    }
                }

                if (items.Count > 0)
                {
                    //allAssociationItems.AddRange(items);
                    this.associations.AddRange(items);
                }
            }
        }
Ejemplo n.º 5
0
        GenerateAssociationPropertyNames(AssocationType assocationType, AssociationItem associationItem)
        {
            string ownerPropertyName;
            AssociationPropertyType ownerPropertyType;
            string targetPropertyName;
            AssociationPropertyType targetPropertyType;

            if (assocationType == AssocationType.OneToOne)
            {
                //TODO: Generating property name - is OK ??
                //ownerPropertyName = NormalizeDBName(associationItem.ForeignKeyColumn.Owner.ForeignTable.Name);
                ownerPropertyName  = NormalizeDBName(associationItem.ForeignKeyColumn.Name ?? associationItem.ForeignKeyColumn.Owner.ForeignTable.Name);
                ownerPropertyType  = AssociationPropertyType.EntityReference;
                targetPropertyName = string.Empty;
                targetPropertyType = AssociationPropertyType.None;
            }
            else
            {
                if (assocationType == AssocationType.ManyToMany)
                {
                    ownerPropertyName  = BuildEntitySetPropertyName(NormalizeDBName(associationItem.TargetSetting.Table.Name));
                    targetPropertyName = BuildEntitySetPropertyName(NormalizeDBName(associationItem.OwnerSetting.Table.Name));
                    ownerPropertyType  = AssociationPropertyType.EntitySet;
                    targetPropertyType = AssociationPropertyType.EntitySet;
                }
                else
                {
                    ownerPropertyName  = BuildEntitySetPropertyName(NormalizeDBName(associationItem.TargetSetting.Table.Name));
                    ownerPropertyType  = AssociationPropertyType.EntitySet;
                    targetPropertyName = NormalizeDBName(associationItem.OwnerSetting.Table.Name);
                    targetPropertyType = AssociationPropertyType.EntityReference;
                }
            }

            return(new Tuple <string, AssociationPropertyType, string, AssociationPropertyType>(ownerPropertyName,
                                                                                                ownerPropertyType, targetPropertyName, targetPropertyType));
        }