internal void AddUpdateQueriesToDataComponent(CodeTypeDeclaration classDeclaration, string dataSourceClassName, CodeDomProvider codeProvider) { if (this.designTable == null) { throw new InternalException("Design Table should not be null."); } if (StringUtil.EmptyOrSpace(dataSourceClassName)) { throw new InternalException("Data source class name should not be empty"); } if (this.designTable.HasAnyUpdateCommand) { UpdateCommandGenerator generator = new UpdateCommandGenerator(this.codeGenerator) { CodeProvider = codeProvider, DeclarationOnly = this.declarationsOnly, MethodSource = this.designTable.MainSource as DbSource, DesignTable = this.designTable }; if (this.designTable.Connection != null) { generator.ProviderFactory = ProviderManager.GetFactory(this.designTable.Connection.Provider); } else if (!this.declarationsOnly) { throw new InternalException("DesignTable.Connection should not be null to generate update query statements."); } CodeMemberMethod method = null; generator.MethodName = DataComponentNameHandler.UpdateMethodName; generator.ActiveCommand = generator.MethodSource.UpdateCommand; generator.MethodType = MethodTypeEnum.GenericUpdate; generator.UpdateParameterTypeReference = CodeGenHelper.GlobalType(typeof(DataTable)); generator.UpdateParameterName = "dataTable"; generator.UpdateParameterTypeName = CodeGenHelper.GetTypeName(codeProvider, dataSourceClassName, this.designTable.GeneratorTableClassName); if (this.codeGenerator.DataSetNamespace != null) { generator.UpdateParameterTypeName = CodeGenHelper.GetTypeName(this.codeGenerator.CodeProvider, this.codeGenerator.DataSetNamespace, generator.UpdateParameterTypeName); } method = generator.Generate(); if (method != null) { classDeclaration.Members.Add(method); } generator.UpdateParameterTypeReference = CodeGenHelper.GlobalType(typeof(DataSet)); generator.UpdateParameterName = "dataSet"; generator.UpdateParameterTypeName = dataSourceClassName; if (this.codeGenerator.DataSetNamespace != null) { generator.UpdateParameterTypeName = CodeGenHelper.GetTypeName(this.codeGenerator.CodeProvider, this.codeGenerator.DataSetNamespace, generator.UpdateParameterTypeName); } method = generator.Generate(); if (method != null) { classDeclaration.Members.Add(method); } generator.UpdateParameterTypeReference = CodeGenHelper.GlobalType(typeof(DataRow)); generator.UpdateParameterName = "dataRow"; generator.UpdateParameterTypeName = null; method = generator.Generate(); if (method != null) { classDeclaration.Members.Add(method); } generator.UpdateParameterTypeReference = CodeGenHelper.GlobalType(typeof(DataRow), 1); generator.UpdateParameterName = "dataRows"; generator.UpdateParameterTypeName = null; method = generator.Generate(); if (method != null) { classDeclaration.Members.Add(method); } if (generator.MethodSource.GenerateShortCommands) { generator.MethodType = MethodTypeEnum.ColumnParameters; generator.ActiveCommand = generator.MethodSource.DeleteCommand; if (generator.ActiveCommand != null) { generator.MethodName = DataComponentNameHandler.DeleteMethodName; generator.UpdateCommandName = "DeleteCommand"; generator.ParameterOption = this.languageSupportsNullables ? ParameterGenerationOption.ClrTypes : ParameterGenerationOption.Objects; method = generator.Generate(); if (method != null) { classDeclaration.Members.Add(method); } } generator.ActiveCommand = generator.MethodSource.InsertCommand; if (generator.ActiveCommand != null) { generator.MethodName = DataComponentNameHandler.InsertMethodName; generator.UpdateCommandName = "InsertCommand"; generator.ParameterOption = this.languageSupportsNullables ? ParameterGenerationOption.ClrTypes : ParameterGenerationOption.Objects; method = generator.Generate(); if (method != null) { classDeclaration.Members.Add(method); } } generator.ActiveCommand = generator.MethodSource.UpdateCommand; if (generator.ActiveCommand != null) { generator.MethodName = DataComponentNameHandler.UpdateMethodName; generator.UpdateCommandName = "UpdateCommand"; generator.ParameterOption = this.languageSupportsNullables ? ParameterGenerationOption.ClrTypes : ParameterGenerationOption.Objects; method = generator.Generate(); if (method != null) { classDeclaration.Members.Add(method); method = null; generator.GenerateOverloadWithoutCurrentPKParameters = true; try { method = generator.Generate(); } finally { generator.GenerateOverloadWithoutCurrentPKParameters = false; } if (method != null) { classDeclaration.Members.Add(method); } } } } } }
internal void AddUpdateQueriesToDataComponent(CodeTypeDeclaration classDeclaration, string dataSourceClassName, CodeDomProvider codeProvider) { if (this.designTable == null) { throw new InternalException("Design Table should not be null."); } if (StringUtil.EmptyOrSpace(dataSourceClassName)) { throw new InternalException("Data source class name should not be empty"); } if (this.designTable.HasAnyUpdateCommand) { UpdateCommandGenerator generator = new UpdateCommandGenerator(this.codeGenerator) { CodeProvider = codeProvider, DeclarationOnly = this.declarationsOnly, MethodSource = this.designTable.MainSource as DbSource, DesignTable = this.designTable }; if (this.designTable.Connection != null) { generator.ProviderFactory = ProviderManager.GetFactory(this.designTable.Connection.Provider); } else if (!this.declarationsOnly) { throw new InternalException("DesignTable.Connection should not be null to generate update query statements."); } CodeMemberMethod method = null; generator.MethodName = DataComponentNameHandler.UpdateMethodName; generator.ActiveCommand = generator.MethodSource.UpdateCommand; generator.MethodType = MethodTypeEnum.GenericUpdate; generator.UpdateParameterTypeReference = CodeGenHelper.GlobalType(typeof(DataTable)); generator.UpdateParameterName = "dataTable"; generator.UpdateParameterTypeName = CodeGenHelper.GetTypeName(codeProvider, dataSourceClassName, this.designTable.GeneratorTableClassName); if (this.codeGenerator.DataSetNamespace != null) { generator.UpdateParameterTypeName = CodeGenHelper.GetTypeName(this.codeGenerator.CodeProvider, this.codeGenerator.DataSetNamespace, generator.UpdateParameterTypeName); } method = generator.Generate(); if (method != null) { classDeclaration.Members.Add(method); } generator.UpdateParameterTypeReference = CodeGenHelper.GlobalType(typeof(DataSet)); generator.UpdateParameterName = "dataSet"; generator.UpdateParameterTypeName = dataSourceClassName; if (this.codeGenerator.DataSetNamespace != null) { generator.UpdateParameterTypeName = CodeGenHelper.GetTypeName(this.codeGenerator.CodeProvider, this.codeGenerator.DataSetNamespace, generator.UpdateParameterTypeName); } method = generator.Generate(); if (method != null) { classDeclaration.Members.Add(method); } generator.UpdateParameterTypeReference = CodeGenHelper.GlobalType(typeof(DataRow)); generator.UpdateParameterName = "dataRow"; generator.UpdateParameterTypeName = null; method = generator.Generate(); if (method != null) { classDeclaration.Members.Add(method); } generator.UpdateParameterTypeReference = CodeGenHelper.GlobalType(typeof(DataRow), 1); generator.UpdateParameterName = "dataRows"; generator.UpdateParameterTypeName = null; method = generator.Generate(); if (method != null) { classDeclaration.Members.Add(method); } if (generator.MethodSource.GenerateShortCommands) { generator.MethodType = MethodTypeEnum.ColumnParameters; generator.ActiveCommand = generator.MethodSource.DeleteCommand; if (generator.ActiveCommand != null) { generator.MethodName = DataComponentNameHandler.DeleteMethodName; generator.UpdateCommandName = "DeleteCommand"; generator.ParameterOption = this.languageSupportsNullables ? ParameterGenerationOption.ClrTypes : ParameterGenerationOption.Objects; method = generator.Generate(); if (method != null) { classDeclaration.Members.Add(method); } } generator.ActiveCommand = generator.MethodSource.InsertCommand; if (generator.ActiveCommand != null) { generator.MethodName = DataComponentNameHandler.InsertMethodName; generator.UpdateCommandName = "InsertCommand"; generator.ParameterOption = this.languageSupportsNullables ? ParameterGenerationOption.ClrTypes : ParameterGenerationOption.Objects; method = generator.Generate(); if (method != null) { classDeclaration.Members.Add(method); } } generator.ActiveCommand = generator.MethodSource.UpdateCommand; if (generator.ActiveCommand != null) { generator.MethodName = DataComponentNameHandler.UpdateMethodName; generator.UpdateCommandName = "UpdateCommand"; generator.ParameterOption = this.languageSupportsNullables ? ParameterGenerationOption.ClrTypes : ParameterGenerationOption.Objects; method = generator.Generate(); if (method != null) { classDeclaration.Members.Add(method); method = null; generator.GenerateOverloadWithoutCurrentPKParameters = true; try { method = generator.Generate(); } finally { generator.GenerateOverloadWithoutCurrentPKParameters = false; } if (method != null) { classDeclaration.Members.Add(method); } } } } } }