コード例 #1
0
        /// <summary>
        /// Generates the custom column code.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="fullTableName">Full name of the table.</param>
        /// <param name="columnName">Name of the column.</param>
        private void GenerateCustomColumnCode(System.Data.Entity.Migrations.Utilities.IndentedTextWriter writer, string fullTableName, string columnName)
        {
            string tableName = fullTableName.Replace("dbo.", string.Empty);

            if (dbContextEntities.ContainsKey(tableName))
            {
                Type tableType = dbContextEntities[tableName];
                if (tableType != null)
                {
                    MemberInfo mi = tableType.GetMember(columnName).FirstOrDefault();

                    if (mi != null)
                    {
                        AlternateKeyAttribute attribute = mi.GetCustomAttribute <AlternateKeyAttribute>();
                        if (attribute != null)
                        {
                            writer.WriteLine("CreateIndex( \"" + fullTableName + "\", \"" + columnName + "\", true );");
                            writer.WriteLine("");
                        }
                    }
                    else
                    {
                        // probably not found if this is the Down() migration
                    }
                }
            }
            else
            {
                // probably not found if this is the Down() migration
            }
        }
コード例 #2
0
        /// <summary>
        /// Generates the custom column code.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="fullTableName">Full name of the table.</param>
        /// <param name="columnName">Name of the column.</param>
        private void GenerateCustomColumnCode(System.Data.Entity.Migrations.Utilities.IndentedTextWriter writer, string fullTableName, string columnName)
        {
            string tableName = fullTableName.Replace("dbo.", string.Empty);

            Type tableType = null;

            try
            {
                tableType = tableNameLookup[tableName];
            }
            catch (Exception ex)
            {
                writer.WriteLine("// TableName: " + tableName);
                writer.WriteLine("// " + ex.Message);
            }
            if (tableType != null)
            {
                MemberInfo mi = tableType.GetMember(columnName).FirstOrDefault();

                if (mi != null)
                {
                    AlternateKeyAttribute attribute = mi.GetCustomAttribute <AlternateKeyAttribute>();
                    if (attribute != null)
                    {
                        writer.WriteLine("CreateIndex( \"" + fullTableName + "\", \"" + columnName + "\", true );");
                    }
                }
                else
                {
                    // probably not found if this is the Down() migration
                }
            }
            else
            {
                // probably not found if this is the Down() migration
            }
        }