TemplateScope

Apr 21, 2014 at 1:52 PM
Edited Apr 21, 2014 at 2:24 PM
Hi, I meet some problems.

Imagine that a reader has many books, and one book has some chapters and bookmarks.
Then I just want to sync specific reader informations, the reader' books, the specific books' chapters and bookmarks.

Now, I can get specific reader and the specific reader' books. but I get all books chapters and bookmarks.

To sovle it, I plan to add ReaderID in the BookChapter table and the Bookmark table.
Any other solution?


The existing Code:
Server:
    // make the relationship beetween my database filters and the arg sended by the clients
    config.AddFilterParameterConfiguration("readerId", "Reader", "@ID", typeof(System.Guid));

    config.AddFilterParameterConfiguration("readerId", "Book", "@ReaderID", typeof(System.Guid));
Client:
    Guid readerId = new Guid("75821246-0F86-4D05-95B0-CC090971CFD7");
    string id = readerId.ToString();
    // Need to specify the filter paramters.
    this.SyncContext.AddScopeParameters("readerId", id);
the configuration file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <section name="SyncConfiguration" type="Microsoft.Synchronization.ClientServices.Configuration.SyncConfigurationSection, SyncSvcUtil, Version=3.8.3.1, Culture=neutral, PublicKeyToken=null" allowLocation="true" allowDefinition="Everywhere" allowExeDefinition="MachineToApplication" overrideModeDefault="Allow" restartOnExternalChanges="true" requirePermission="true" />
    </configSections>
    <SyncConfiguration>
        <SyncScopes>
            <SyncScope Name="TemplateScope" SchemaName="" IsTemplateScope="true"
                EnableBulkApplyProcedures="false">
                <SyncTables>
                    <SyncTable Name="[BookChapter]" GlobalName="" SchemaName="" IncludeAllColumns="true"
                        FilterClause="">
                        <SyncColumns>
                            <SyncColumn Name="ID" GlobalName="" SqlType="uniqueidentifier"
                                IsPrimaryKey="true" IsNullable="false" />
                            <SyncColumn Name="Title" GlobalName="" SqlType="nvarchar" IsPrimaryKey="false"
                                IsNullable="false" />
                            <SyncColumn Name="Number" GlobalName="" SqlType="int" IsPrimaryKey="false"
                                IsNullable="false" />
                            <SyncColumn Name="BookID" GlobalName="" SqlType="uniqueidentifier"
                                IsPrimaryKey="false" IsNullable="false" />
                            <SyncColumn Name="Content" GlobalName="" SqlType="nvarchar" IsPrimaryKey="false"
                                IsNullable="false" />
                        </SyncColumns>
                    </SyncTable>
                    <SyncTable Name="[Bookmark]" GlobalName="" SchemaName="" IncludeAllColumns="true"
                        FilterClause="">
                        <SyncColumns>
                            <SyncColumn Name="ID" GlobalName="" SqlType="uniqueidentifier"
                                IsPrimaryKey="true" IsNullable="false" />
                            <SyncColumn Name="Number" GlobalName="" SqlType="int" IsPrimaryKey="false"
                                IsNullable="false" />
                            <SyncColumn Name="Offset" GlobalName="" SqlType="int" IsPrimaryKey="false"
                                IsNullable="false" />
                            <SyncColumn Name="BookID" GlobalName="" SqlType="uniqueidentifier"
                                IsPrimaryKey="false" IsNullable="false" />
                            <SyncColumn Name="ChapterID" GlobalName="" SqlType="uniqueidentifier"
                                IsPrimaryKey="false" IsNullable="false" />
                        </SyncColumns>
                    </SyncTable>
                    <SyncTable Name="[Book]" GlobalName="" SchemaName="" IncludeAllColumns="true"
                        FilterClause="[side].ReaderID = @ReaderID">
                        <SyncColumns>
                            <SyncColumn Name="ID" GlobalName="" SqlType="uniqueidentifier"
                                IsPrimaryKey="true" IsNullable="false" />
                            <SyncColumn Name="Title" GlobalName="" SqlType="nvarchar" IsPrimaryKey="false"
                                IsNullable="false" />
                            <SyncColumn Name="Author" GlobalName="" SqlType="nvarchar" IsPrimaryKey="false"
                                IsNullable="true" />
                            <SyncColumn Name="ISBN" GlobalName="" SqlType="nvarchar" IsPrimaryKey="false"
                                IsNullable="true" />
                            <SyncColumn Name="Press" GlobalName="" SqlType="nvarchar" IsPrimaryKey="false"
                                IsNullable="true" />
                            <SyncColumn Name="LatestReadingTime" GlobalName="" SqlType="datetime"
                                IsPrimaryKey="false" IsNullable="true" />
                            <SyncColumn Name="ReaderID" GlobalName="" SqlType="uniqueidentifier"
                                IsPrimaryKey="false" IsNullable="false" />
                            <SyncColumn Name="RawPhoto" GlobalName="" SqlType="varbinary"
                                IsPrimaryKey="false" IsNullable="true" />
                        </SyncColumns>
                        <FilterColumns>
                            <FilterColumn Name="ReaderID" />
                        </FilterColumns>
                        <FilterParameters>
                            <FilterParameter Name="@ReaderID" SqlType="uniqueidentifier"
                                DataSize="0" />
                        </FilterParameters>
                    </SyncTable>
                    <SyncTable Name="[Reader]" GlobalName="" SchemaName="" IncludeAllColumns="true"
                        FilterClause="[side].ID = @ID">
                        <SyncColumns>
                            <SyncColumn Name="ID" GlobalName="" SqlType="uniqueidentifier"
                                IsPrimaryKey="true" IsNullable="false" />
                        </SyncColumns>
                        <FilterColumns>
                            <FilterColumn Name="ID" />
                        </FilterColumns>
                        <FilterParameters>
                            <FilterParameter Name="@ID" SqlType="uniqueidentifier" DataSize="0" />
                        </FilterParameters>
                    </SyncTable>
                </SyncTables>
            </SyncScope>
        </SyncScopes>
    </SyncConfiguration>
</configuration>
Coordinator
Apr 22, 2014 at 7:39 AM
Indeed, you can add ReaderID in the BookChapter table and the Bookmark table to resolve this issue.

By the way, you can make a filter like this:
In BookChapter you can have something like :

[side].BookID in (Select ID from Book Where ReaderId = @readerID)

Sebastien
Apr 22, 2014 at 9:43 AM
Ok, thank you!

Joe