What are the challenges you face when working across database platforms? Take the survey
Options

Missing Field from Where Clause

jimmypoohjimmypooh Posts: 12
I'm using the compaire and passing it a where clause for each mapping. However, not all tabled have the field I'm using in the where clause. Is there a way to tell the comparer to ignore the where clause if it errors?

Or I guess the better question is how do I check the TableMapping if that particular where clause will be viable (ie if a certain field exists).

Comments

  • Options
    Thanks for your query.
    There isn't a particularly quick way of doing this, but one option is as below:
    private static void AddWhereClause(TableMappings mappings)
    		{
    			foreach (TableMapping mapping in mappings) 
    			{ 
    				if (mapping.Obj1.FullyQualifiedName=="[dbo].[ActionHistory]") 
    				{
    
                        foreach (FieldMapping m in mapping.FieldMappings)
                        {
                            if (m.Obj1.Name == "ActionDate")
                            {
                                mapping.Include = true;
                                mapping.Where = new WhereClause("RecordID>=2");
                            }
                        }
                    }
    				else
    				{
    					mapping.Include = false;
    				}
    			}
    		}
    


    In this instance, as I iterate around the mappings collection I'm checking for a certain table name. Within that check, I'm going through the fields collection to then see if a specific column exists.

    You can perhaps tweak this so the column or table level check looks at your where clause to automate it to a certain extent.

    Hope that helps.
    Systems Software Engineer

    Redgate Software

Sign In or Register to comment.