public override void GenerateEntities(string filePrefix, string nameSpace, DbSyncScopeDescription desc,
                                              Dictionary <string, Dictionary <string, string> > colsMappingInfo,
                                              DirectoryInfo dirInfo, CodeLanguage option, string serviceUri)
        {
            var entitiesCC = new CodeCompileUnit();

            var entityScopeNs = new CodeNamespace(nameSpace);

            // Generate the base class for all the entities which will implement IOfflineEntity
            var baseEntity = CodeDomUtility.CreateIOfflineEntityCustomBaseClass(
                string.IsNullOrEmpty(filePrefix) ? desc.ScopeName : filePrefix,
                false /*isServer*/);

            // Set the base type
            // VB uses different keywords for class and interface inheritence. For it to emit the
            // right keyword it must inherit from object first before the actual interface.
            baseEntity.BaseTypes.Add(new CodeTypeReference(typeof(object)));
            baseEntity.BaseTypes.Add(new CodeTypeReference(Constants.ClientIOfflineEntity));

            entityScopeNs.Types.Add(baseEntity);

            // Generate the entities
            foreach (var table in desc.Tables)
            {
                Dictionary <string, string> curTableMapping = null;
                colsMappingInfo.TryGetValue(table.UnquotedGlobalName, out curTableMapping);

                // Generate the actual entity
                var entityDecl = CodeDomUtility.GetEntityForTableDescription(table, true, curTableMapping);

                // Set the base type
                entityDecl.BaseTypes.Add(baseEntity.Name);

                //Add it to the overall scope
                entityScopeNs.Types.Add(entityDecl);
            }

            entitiesCC.Namespaces.Add(entityScopeNs);

            // Generate the files
            CodeDomUtility.SaveCompileUnitToFile(entitiesCC, option,
                                                 CodeDomUtility.GenerateFileName(desc.ScopeName, dirInfo, filePrefix, "Entities", option));
        }
        private static CodeCompileUnit GenerateEntitiesCompileUnit(string prefix, string nameSpace,
                                                                   DbSyncScopeDescription desc, Dictionary <string, Dictionary <string, string> > colsMappingInfo)
        {
            var cc = new CodeCompileUnit();

            var scopeNs = new CodeNamespace(nameSpace);

            // Generate the outer most entity
            var wrapperEntity = new CodeTypeDeclaration(
                string.Format(Constants.ServiceOuterEntityNameFormat,
                              string.IsNullOrEmpty(prefix) ? desc.ScopeName : prefix)
                );

            wrapperEntity.CustomAttributes.Add(
                new CodeAttributeDeclaration(Constants.ServiceSyncScopeAttributeDefinition));

            // Generate the base class for all the entities which will implement IOfflineEntity
            var baseEntity = CodeDomUtility.CreateIOfflineEntityCustomBaseClass(
                string.IsNullOrEmpty(prefix) ? desc.ScopeName : prefix,
                true /*isServer*/);

            // Set the base type
            // VB uses different keywords for class and interface inheritence. For it to emit the
            // right keyword it must inherit from object first before the actual interface.
            baseEntity.BaseTypes.Add(new CodeTypeReference(typeof(object)));
            baseEntity.BaseTypes.Add(new CodeTypeReference(Constants.ServiceIOfflineEntity));

            scopeNs.Types.Add(baseEntity);

            // Generate the entities
            foreach (var table in desc.Tables)
            {
                Dictionary <string, string> curTableMapping = null;
                colsMappingInfo.TryGetValue(table.UnquotedGlobalName, out curTableMapping);

                var tableName      = CodeDomUtility.SanitizeName(table.UnquotedGlobalName);
                var icollReference = new CodeTypeReference(typeof(ICollection <>));

                // Generate the private field
                var entityReference = new CodeTypeReference(tableName);
                icollReference.TypeArguments.Clear();
                icollReference.TypeArguments.Add(entityReference);

                var itemCollectionField = new CodeMemberField(icollReference,
                                                              string.Format(Constants.EntityFieldNameFormat, tableName));
                itemCollectionField.Attributes = MemberAttributes.Private;
                wrapperEntity.Members.Add(itemCollectionField);

                // Generate the actual entity
                var entityDecl = CodeDomUtility.GetEntityForTableDescription(table, false /*addKeyAttributes*/,
                                                                             curTableMapping);
                entityDecl.BaseTypes.Add(baseEntity.Name);

                var syncEntityAttributeDeclaration = new CodeAttributeDeclaration(Constants.ServiceSyncEntityAttribute,
                                                                                  new CodeAttributeArgument("TableGlobalName",
                                                                                                            new CodeSnippetExpression("\"" + CodeDomUtility.SanitizeName(table.UnquotedGlobalName) + "\"")),
                                                                                  // table.LocalName is quoted and contains the schema name.
                                                                                  new CodeAttributeArgument("TableLocalName", new CodeSnippetExpression("\"" + table.LocalName + "\"")),
                                                                                  new CodeAttributeArgument("KeyFields",
                                                                                                            new CodeSnippetExpression("\"" +
                                                                                                                                      String.Join(",", table.PkColumns.
                                                                                                                                                  Select(
                                                                                                                                                      e =>
                                                                                                                                                      CodeDomUtility.SanitizeName(
                                                                                                                                                          GetKeyColumnName(e.UnquotedName, curTableMapping)))
                                                                                                                                                  .ToArray()) +
                                                                                                                                      "\"")));

                // Use the PkColumns property to generate the column list for the KeyFields property.
                // This is important as it is used later to generate SyncId's for rows and ordering is important.
                entityDecl.CustomAttributes.Add(syncEntityAttributeDeclaration);

                scopeNs.Types.Add(entityDecl);
            }

            scopeNs.Types.Add(wrapperEntity);
            cc.Namespaces.Add(scopeNs);
            return(cc);
        }