locked
CreateSchema data type mapping problems RRS feed

  • Question

  • Hi

    I have a strongly typed dataset with a table with that has a primary key with datatype "System.String" and MaxLength "32"

    When I cann SqlCeClientSyncProvider.CreateSchema(new SyncTable("table"), new SyncSchema(myDataset)), it fails telling me long columns cannot be indexed.

    The reason is that it's mapped the String to NText which cannot be a primary key.

    I'm guessing this is a bug in MSSync... but if not can you tell me how I can change this mapping?

    Thanks,
    Mark.

    • Moved by Max Wang_1983 Friday, April 22, 2011 10:31 PM forum consolidation (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Tuesday, July 3, 2007 11:34 AM

Answers

  •  

    Hi Mark,

     

    you need to explictly set the ProviderDataType for the column, the default is null and will be mapped to Ntext on the SSCE client. this is why you got the exception.

     

    A short code snippet as followings:

     

    SyncSchema customers = new SyncSchema();

                    customers.Tables.Add("Customers");

                    customers.Tables[0].Columns.Add("CustomerID");

                    customers.Tables[0].Columns.Add("CompanyName");

                    customers.Tables[0].Columns.Add("Contact");

                    customers.Tables[0].Columns[0].DataType = Type.GetType("System.String");

                    customers.Tables[0].Columns[1].DataType = Type.GetType("System.String");

                    customers.Tables[0].Columns[2].DataType = Type.GetType("System.String");

     

                    customers.Tables[0].PrimaryKey = new string[] { "CustomerID" };

     

                    customers.Tables[0].Columns[0].ProviderDataType = "nvarchar";

                    customers.Tables[0].Columns[0].MaxLength = 50;

     

                    serverProvider.Schema = customers;

     

    Cheers,

     

    Yunwen

    Tuesday, July 3, 2007 6:31 PM
    Moderator