private void RunInsertOrUpdateWithDuplicatePropertyMappings(TableB oldObject, TableB newObject)
        {
            try
            {
                SimpleSaveExtensions.ThrowOnMultipleWriteablePropertiesAgainstSameColumn = false;
                var logger = CreateMockLogger();

                try
                {
                    using (IDbConnection connection = new SqlConnection())
                    {
                        connection.Update(oldObject, newObject);
                    }
                }
                catch (InvalidOperationException ioe)
                {
                    if (ioe.Message.Contains("both contain properties mapped to column"))
                    {
                        throw;
                    }
                }

                var scripts = logger.Scripts;
                Assert.AreEqual(1, scripts.Count);

                var script = scripts[0];
                var sql = script.Buffer.ToString();
                Assert.AreEqual(sql.IndexOf("Name"), sql.LastIndexOf("Name"), "Column appears more than once.");
            }
            finally
            {
                SimpleSaveExtensions.ThrowOnMultipleWriteablePropertiesAgainstSameColumn = true;
            }
        }
 public void throws_on_insert_with_duplicate_property_mappings_by_default()
 {
     var newObject = new TableB() { Name = "Captain Jack Sparrow" };
     using (IDbConnection connection = new SqlConnection())
     {
         connection.Create(newObject);
     }
 }
 public void throws_on_update_with_duplicate_property_mappings_by_default()
 {
     var oldObject = new TableB() { Name = "Captain Barbosa" };
     var newObject = new TableB() { Name = "Captain Jack Sparrow" };
     using (IDbConnection connection = new SqlConnection())
     {
         connection.Update(oldObject, newObject);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Returns the hash code for this instance.
        /// </summary>
        public override int GetHashCode()
        {
            var h1 = TableA.GetHashCode();
            var h2 = TableB.GetHashCode();

            // sort
            if (h1 < h2)
            {
                unchecked
                {
                    return((527 + h1) * 31 + h2);
                }
            }
            else
            {
                unchecked
                {
                    return((527 + h2) * 31 + h1);
                }
            }
        }
Exemplo n.º 5
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat(JoinClause.ToString()).AppendLine();

            if (TableA is gsSubQueryFromTerm)
            {
                var subQry = TableA as gsSubQueryFromTerm;
                subQry.SubQuery.QryName = $"subQry{gsSelectQuery.GetNextID()}";

                sb.AppendLine();
                sb.AppendLine(subQry.SubQuery.ToString());
            }

            if (TableB is gsSubQueryFromTerm)
            {
                var subQry = TableB as gsSubQueryFromTerm;
                subQry.SubQuery.QryName = $"subQry{gsSelectQuery.GetNextID()}";

                sb.AppendLine();
                sb.AppendLine(subQry.SubQuery.ToString());
            }

            sb.AppendLine($"{QryName}.FromClause.Join(JoinType.{JoinType.ToString()}, {TableA.ToString()}, {TableB.ToString()}, {JoinClause.WhereClauseName});");
            return(sb.ToString());
        }
Exemplo n.º 6
0
 /// <summary>
 /// Returns the string representation of this instance.
 /// </summary>
 public override string ToString()
 {
     return(String.Format("{0}:{1}", TableA.ToString(), TableB.ToString()));
 }
        private void RunInsertOrUpdateWithDuplicatePropertyMappings(TableB oldObject, TableB newObject)
        {
            try
            {
                SimpleSaveExtensions.ThrowOnMultipleWriteablePropertiesAgainstSameColumn = false;
                var logger = CreateMockLogger();

                try
                {
                    using (IDbConnection connection = new SqlConnection())
                    {
                        connection.Update(oldObject, newObject);
                    }
                }
                catch (InvalidOperationException ioe)
                {
                    if (ioe.Message.Contains("both contain properties mapped to column"))
                    {
                        throw;
                    }
                }

                var scripts = logger.Scripts;
                Assert.AreEqual(1, scripts.Count);

                var script = scripts[0];
                var sql    = script.Buffer.ToString();
                Assert.AreEqual(sql.IndexOf("Name"), sql.LastIndexOf("Name"), "Column appears more than once.");
            }
            finally
            {
                SimpleSaveExtensions.ThrowOnMultipleWriteablePropertiesAgainstSameColumn = true;
            }
        }
 public void does_not_throw_with_duplicate_property_mappings_when_warning_disabled_does_not_emit_script_with_duplicate_update_columns()
 {
     var oldObject = new TableB() { Name = "Captain Barbosa" };
     var newObject = new TableB() { Name = "Captain Jack Sparrow" };
     RunInsertOrUpdateWithDuplicatePropertyMappings(oldObject, newObject);
 }
Exemplo n.º 9
0
 internal bool Equals(DB3 tableA, DB3 tableB)
 {
     return(TableA.Equals(tableA) && TableB.Equals(tableB));
 }