Sync Framework v2 CTP2 - A few questions regarding the schema objects RRS feed

  • Question

  • 1. Why is it that one e.g could enumerate through syncSchema.SchemaDataset.Tables but not through syncschema.Tables?
    Other examples are  the columns or the foreignkey collection.

    2. In addition, I find it confusing that several syncobjects are not derived from corresponding data objects (e.g. SyncSchemaColumn and DataColumn). This -for example- prevents one from adding a SyncSchema.Tables["table"].Columns["column"] to SchemaDatasets.Relations.

    3. Overload #5 of the ForeignKeyConstraint constructor:
    public ForeignKeyConstraint (string constraintName, string parentTableName, string [] parentColumnNames, string [] childColumnNames, AcceptRejectRule acceptRejectRule, Rule deleteRule, Rule updateRule);
    doesn't seem to work at all. If I create a foreignkeyconstraint that way, I receive "Object not set" exception when I use it. It seems that this overload doesn't create all internal objects.



    • Moved by Max Wang_1983 Thursday, April 21, 2011 11:30 PM forum consolidation (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Thursday, September 3, 2009 7:54 PM

All replies

  • #1 - This could be helpful, but most of them have Count and index access, so you could write a for loop to iterate over them.

    #2 - You have access to the System.Data objects via syncSchema.SchemaDataset, so those can be accessed using SyncSchema.SchemaDataSet.Tables["table"].Columns["column"]. 

    #3 - Could you provide a sample of the input you are giving to this function when you see this exception?

    Tuesday, September 8, 2009 6:22 PM
  • #1 - I agree. I had just wondered why this one is different from the rest. IMHO such different behavior unnecessarily complicates the usage of a framework.

    #2 - I agree, too. It's just that one has to access a different object where one would expect to use the already supplied one (e.g. in an eventarg). One could argue this is just cosmetics but I would like to refer to #1 above

    Please note that these statements are only my personal opinion

    #3 - Here is the version that works fine:
    public static void AddForeignKeyConstraint(SyncSchema syncSchema, string constraintName, string parentTable, string parentColumn, string childTable, string childColumn)
        DataColumn parentDataColumn = syncSchema.SchemaDataSet.Tables[parentTable].Columns[parentColumn];
        DataColumn childDataColumn = syncSchema.SchemaDataSet.Tables[childTable].Columns[childColumn];
        ForeignKeyConstraint foreignConstraint = new ForeignKeyConstraint(constraintName, parentDataColumn, childDataColumn);
        foreignConstraint.AcceptRejectRule = AcceptRejectRule.None;
        foreignConstraint.DeleteRule = Rule.None;
        foreignConstraint.UpdateRule = Rule.None;
    This one here (using overload #5) :
    public static void AddForeignKeyConstraint(SyncSchema syncSchema, string constraintName, string parentTable, string parentColumn, string childTable, string childColumn)
        ForeignKeyConstraint foreignConstraint = new ForeignKeyConstraint(constraintName, parentTable, 
                                                        new string[] {parentColumn}, 
                                                        new string[] {childColumn}, 
                                                        AcceptRejectRule.None, Rule.None, Rule.None);
        syncSchema.SchemaDataSet.Tables[childTable].Constraints.AddRange(new ForeignKeyConstraint[]{ foreignConstraint});
    fires a Sytem.NullReferenceException
    Stack Trace:
       at System.Data.DataKey.CheckState()
       at System.Data.ForeignKeyConstraint.NonVirtualCheckState()
       at System.Data.ForeignKeyConstraint.CheckState()
       at System.Data.Constraint.CheckStateForProperty()
       at System.Data.ForeignKeyConstraint.get_RelatedTable()
       at System.Data.ConstraintCollection.Add(Constraint constraint, Boolean addUniqueWhenAddingForeign)
       at System.Data.ConstraintCollection.AddRange(Constraint[] constraints)
       at Workstamp.Synchronisation.SyncUtility.AddForeignKeyConstraint(SyncSchema syncSchema, String constraintName, String parentTable, String parentColumn, String childTable, String childColumn) in N:\VS2008\WorkStamp\WorkstampTest\Synchronisation\SyncUtility.cs:line 26


    Wednesday, September 9, 2009 2:24 PM