Beispiel #1
0
        private string GetViewSelectCommand()
        {
            List <string> columns = new List <string>();

            //System.Data.Common.DbConnection con = ConnectionManager.Connection;
            foreach (ColumnInfo ci in TableInfo.Columns)
            {
                if (ci.IsPrimaryKey)
                {
                    uxGrid.MasterTableView.DataKeyNames = new string[] { ci.Title != "" ? ci.Title : ci.ColumnName };
                }
                ForeignKeyRelation fk = ci.ForeignKeyRelation;
                if (fk != null)
                {
                    TableInfo ti         = SchemaUtility.GetTable(fk.PKTable);
                    string    nameColumn = ti.GetNameColumn().ColumnName;
                    columns.Add("( Select  [" + nameColumn + "] From " + fk.PKTable + " Where " + fk.PKTable + ".[" + fk.PKField + "] =  " + TableName + ".[" + fk.FKField + "]  ) ");
                    break;
                }
                else
                {
                    columns.Add(ci.ColumnName + " as [" + ci.Title + "]");//+ " as [" + ci.Title + "]");
                }
            }
            return("select " + string.Join(",", columns.ToArray()) + " from " + TableName);
        }
Beispiel #2
0
        /// <summary>
        /// Resolves the foreign key property for the specified source type and including type
        /// by using <paramref name="includingType"/> + Id as property name.
        /// </summary>
        /// <param name="sourceType">The source type which should contain the foreign key property.</param>
        /// <param name="includingType">The type of the foreign key relation.</param>
        /// <param name="foreignKeyRelation">The foreign key relationship type.</param>
        /// <returns>The foreign key property for <paramref name="sourceType"/> and <paramref name="includingType"/>.</returns>
        public virtual NonaProperty Resolve(Type sourceType, Type includingType, out ForeignKeyRelation foreignKeyRelation)
        {
            var oneToOneFk = ResolveOneToOne(sourceType, includingType);

            if (oneToOneFk != null)
            {
                foreignKeyRelation = ForeignKeyRelation.OneToOne;
                return(oneToOneFk);
            }

            var oneToManyFk = ResolveOneToMany(sourceType, includingType);

            if (oneToManyFk != null)
            {
                foreignKeyRelation = ForeignKeyRelation.OneToMany;
                return(oneToManyFk);
            }

            var msg = $"Could not resolve foreign key property. Source type '{sourceType.FullName}'; including type: '{includingType.FullName}'.";

            throw new Exception(msg);
        }
 public ForeignKeyInfo(PropertyInfo propertyInfo, ForeignKeyRelation relation)
 {
     PropertyInfo = propertyInfo;
     Relation     = relation;
 }
            /// <summary>
            /// Gets the foreign key property for the specified source type and including type
            /// using the configured <see cref="IForeignKeyPropertyResolver"/>.
            /// </summary>
            /// <param name="sourceType">The source type which should contain the foreign key property.</param>
            /// <param name="includingType">The type of the foreign key relation.</param>
            /// <param name="foreignKeyRelation">The foreign key relationship type.</param>
            /// <returns>The foreign key property for <paramref name="sourceType"/> and <paramref name="includingType"/>.</returns>
            public static PropertyInfo ForeignKeyProperty(Type sourceType, Type includingType, out ForeignKeyRelation foreignKeyRelation)
            {
                var key = $"{sourceType};{includingType}";

                if (!_typeForeignKeyPropertyCache.TryGetValue(key, out var foreignKeyInfo))
                {
                    // Resolve the property and relation.
                    var foreignKeyProperty = _foreignKeyPropertyResolver.ResolveForeignKeyProperty(sourceType, includingType, out foreignKeyRelation);

                    // Cache the info.
                    foreignKeyInfo = new ForeignKeyInfo(foreignKeyProperty, foreignKeyRelation);
                    _typeForeignKeyPropertyCache.TryAdd(key, foreignKeyInfo);
                }

                foreignKeyRelation = foreignKeyInfo.Relation;

                LogReceived?.Invoke($"Resolved property '{foreignKeyInfo.PropertyInfo}' ({foreignKeyInfo.Relation}) as foreign key between '{sourceType}' and '{includingType}'");
                return(foreignKeyInfo.PropertyInfo);
            }
Beispiel #5
0
 public ForeignKeyInfo(DubonProperty propertyInfo, ForeignKeyRelation relation)
 {
     DubonProperty = propertyInfo;
     Relation      = relation;
 }
Beispiel #6
0
        /// <summary>
        /// Resolves the foreign key property for the specified source type and including type
        /// by using <paramref name="includingType"/> + Id as property name.
        /// </summary>
        /// <param name="sourceType">The source type which should contain the foreign key property.</param>
        /// <param name="includingType">The type of the foreign key relation.</param>
        /// <param name="foreignKeyRelation">The foreign key relationship type.</param>
        /// <returns>The foreign key property for <paramref name="sourceType"/> and <paramref name="includingType"/>.</returns>
        public virtual PropertyInfo ResolveForeignKeyProperty(Type sourceType, Type includingType, out ForeignKeyRelation foreignKeyRelation)
        {
            var oneToOneFk = ResolveOneToOne(sourceType, includingType);

            if (oneToOneFk != null)
            {
                foreignKeyRelation = ForeignKeyRelation.OneToOne;
                return(oneToOneFk);
            }

            var oneToManyFk = ResolveOneToMany(sourceType, includingType);

            if (oneToManyFk != null)
            {
                foreignKeyRelation = ForeignKeyRelation.OneToMany;
                return(oneToManyFk);
            }

            throw new InvalidOperationException(
                      $"Could not resolve foreign key property. Source type '{sourceType.FullName}'; including type: '{includingType.FullName}'.");
        }
 public ForeignKeyMapping()
 {
     ForeignKeyRelations = new ForeignKeyRelation[0];
 }
Beispiel #8
0
 public ForeignKeyInfo(NonaProperty propertyInfo, ForeignKeyRelation relation)
 {
     NonaProperty = propertyInfo;
     Relation     = relation;
 }
        /// <summary>
        /// Resolve a propriedade de chave estrangeira para o tipo de fonte especificado e incluindo o tipo
        /// usando <paramref name = "includingType" /> + Id como nome da propriedade.
        /// </summary>
        /// <param name = "sourceType"> O tipo de fonte que deve conter a propriedade da chave estrangeira. </param>
        /// <param name = "includingType"> O tipo da relação de chave estrangeira. </param>
        /// <param name = "ForeignKeyRelation"> O tipo de relação de chave estrangeira. </param>
        /// <returns> A propriedade de chave estrangeira para <paramref name = "sourceType" /> e <paramref name = "includingType" />. </returns>
        public virtual PropertyInfo ResolveForeignKeyProperty(Type sourceType, Type includingType, out ForeignKeyRelation foreignKeyRelation)
        {
            var oneToOneFk = ResolveOneToOne(sourceType, includingType);

            if (oneToOneFk != null)
            {
                foreignKeyRelation = ForeignKeyRelation.OneToOne;
                return(oneToOneFk);
            }

            var oneToManyFk = ResolveOneToMany(sourceType, includingType);

            if (oneToManyFk != null)
            {
                foreignKeyRelation = ForeignKeyRelation.OneToMany;
                return(oneToManyFk);
            }

            throw new InvalidOperationException($"Não foi possível resolver a propriedade da chave estrangeira. Tipo de fonte '{sourceType.FullName}'; incluindo o tipo: '{includingType.FullName}'.");
        }