Error: "Mappings only supports mapping objects."

jbaggaleyjbaggaley Posts: 38
edited June 28, 2006 4:01AM in SQL Toolkit Previous Versions
What does this error mean in the context of trying to create a custom column mapping. I figure it is something to do with the primary key field because in your widget example:
// Create the mappings between a certain table 
                
TableMapping tableMapping = (TableMapping)mappings.Join(db1.Tables["[dbo].[WidgetPrices]"], db2.Tables["[dbo].[WidgetPrices]"]);                 
  
// Set the custom comparison key for the table                 
tableMapping.MatchingMappings.Clear();                
tableMapping.MatchingMappings.Add(tableMapping.FieldMappings["WidgetID"]);  
tableMapping.RefreshMappingStatus();      
             
// Set the where clause for the comparison              
tableMapping.Where = new WhereClause("Active = 'Y'");    
  
// Peform the comparison                
session.CompareDatabases(db1, db2, mappings);
changing "widgetid" to "price" produces the same error.

On my table, I have two columns, a primary key value and a secondary key value which I want to compare them against a table that has a combination of those two as a composite primary key but get this error.
What do I need to change (in sql or my code) to fix this issue - even for the widget sample if i wanted to compare price columns for some reason?

Also, can you confirm if the following are identical because in the help file they are next to each other not a subset of eachother.
TableMappings mappings = new TableMappings();                                 
TableMapping tableMapping = (TableMapping)mappings.Join(
and
SchemaMappings mappings = new SchemaMappings(); 
TableMapping tableMapping =(TableMapping) mappings.TableMappings.Join(
Am I right in presuming that they are interchangeable?

Thanks

Jon
:-)zz[

Comments

  • I know is is possible to map tables based on fields that are not just index fields using comparison keys because the DataCompare gui lets me do it but I cannot quite work out how to do the same thing through the toolkit...
    :-)zz[
  • I was passing in values from a dataset to set the table name and field names. However, the values were not being converted to a string first which didn't give a compile error.
    For future reference to solve:-
    make sure the field name is spelt correctly and that it is being passed as a string.
    As for my other question, the tablemapping and structure.tablemappings do seem functionally identical even though they appear next to each other in the help.

    Hope this helps someone....

    Jon
    :-)zz[
  • david connelldavid connell Silver 1 Posts: 172 Silver 1
    Hi Jon,
    As you found out the fields are case sensitive.
    I believe that Schema mappings are probably what you want to use.
    Schema mappings are a superset of TableMappings.

    I would recomend that you let SQL Data Compare Engine setup the default mappings for you and then afterwards customize it for you requirements. eg
    private static void AddWhereClause(SchemaMappings mappings)
    {
      foreach (TableMapping mapping in mappings.TableMappings) 
      { 
        if ( (mapping.Obj1.FullyQualifiedName=="[dbo].[WidgetPrices]") &&
    	     (mapping.Obj1.ObjectType == ObjectType.Table) )
       { 
          mapping.MatchingMappings.Clear();                
          //tableMapping.MatchingMappings.Add(mapping.FieldMappings["RecordID"]);  
          //tableMapping.MatchingMappings.Add(mapping.FieldMappings["WidgetID"]);  
          mapping.MatchingMappings.Add(mapping.FieldMappings["Price"]);
          mapping.RefreshMappingStatus();      
          mapping.Where = new WhereClause("Price>=51"); 
          mapping.Include=true; 
        }
        else
        {
          mapping.Include = false;
        }
      }
    }
    public void myCode()
    {
    ...
    
      SchemaMappings mappings1 = new SchemaMappings();
      mappings1.CreateMappings(db1, db2);
      AddWhereClause(mappings1);
    ....
    }
    

    if you want to use one of the indexes then call
    mapping.UseIndexForMapping(mapping.IndexMappings[0]);
    mapping.RefreshMappingStatus();
    
    or if you know the indexes name, you could use
    mapping.UseIndexForMapping("IX_WidgetPrices");
    mapping.RefreshMappingStatus();
    
    Hope that helps
    David
  • Now if this example can somehow make it's way into the next version of the documentation.... :D
    :-)zz[
Sign In or Register to comment.