private void GenerateQueries(CodeTypeDeclaration classDeclaration, QueryGenerator queryGenerator) { CodeMemberMethod method = null; if (queryGenerator.DeclarationOnly) { if (!queryGenerator.GenerateGetMethod && (queryGenerator.MethodSource.Modifier != MemberAttributes.Public)) { return; } if (queryGenerator.GenerateGetMethod && (queryGenerator.MethodSource.GetMethodModifier != MemberAttributes.Public)) { return; } } queryGenerator.ContainerParameterType = typeof(DataTable); queryGenerator.ContainerParameterTypeName = CodeGenHelper.GetTypeName(this.codeGenerator.CodeProvider, this.codeGenerator.DataSourceName, this.designTable.GeneratorTableClassName); if (this.codeGenerator.DataSetNamespace != null) { queryGenerator.ContainerParameterTypeName = CodeGenHelper.GetTypeName(this.codeGenerator.CodeProvider, this.codeGenerator.DataSetNamespace, queryGenerator.ContainerParameterTypeName); } queryGenerator.ContainerParameterName = "dataTable"; queryGenerator.ParameterOption = this.languageSupportsNullables ? ParameterGenerationOption.ClrTypes : ParameterGenerationOption.Objects; method = queryGenerator.Generate(); if (method != null) { classDeclaration.Members.Add(method); } }
private string GetParameterTypeName() { if (StringUtil.Empty(this.datasetClassName)) { throw new InternalException("DatasetClassName should not be empty."); } if (!(this.containerParameterType == typeof(DataTable))) { return(this.datasetClassName); } if (StringUtil.Empty(this.tableClassName)) { throw new InternalException("TableClassName should not be empty."); } return(CodeGenHelper.GetTypeName(this.codeProvider, this.datasetClassName, this.tableClassName)); }
public override string ImportSchemaType(XmlSchemaType type, XmlSchemaObject context, XmlSchemas schemas, XmlSchemaImporter importer, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeGenerationOptions options, CodeDomProvider codeProvider) { if (type != null) { if (!(context is XmlSchemaElement)) { return(null); } XmlSchemaElement e = (XmlSchemaElement)context; if (IsDataSet(e)) { if (this.importedTypes[type] != null) { return((string)this.importedTypes[type]); } return(this.GenerateTypedDataSet(e, schemas, compileUnit, mainNamespace, codeProvider)); } if (type is XmlSchemaComplexType) { XmlSchemaComplexType type2 = (XmlSchemaComplexType)type; if (type2.Particle is XmlSchemaSequence) { XmlSchemaObjectCollection items = ((XmlSchemaSequence)type2.Particle).Items; if (((items.Count == 2) && (items[0] is XmlSchemaAny)) && (items[1] is XmlSchemaAny)) { XmlSchemaAny any = (XmlSchemaAny)items[0]; XmlSchemaAny any2 = (XmlSchemaAny)items[1]; if ((any.Namespace == "http://www.w3.org/2001/XMLSchema") && (any2.Namespace == "urn:schemas-microsoft-com:xml-diffgram-v1")) { string ns = null; string str2 = null; foreach (XmlSchemaAttribute attribute in type2.Attributes) { if (attribute.Name == "namespace") { ns = attribute.FixedValue.Trim(); } else if (attribute.Name == "tableTypeName") { str2 = attribute.FixedValue.Trim(); } if ((ns != null) && (str2 != null)) { break; } } if (ns == null) { return(null); } IList list = schemas.GetSchemas(ns); if (list.Count != 1) { return(null); } XmlSchema schema = list[0] as XmlSchema; if ((schema == null) || (schema.Id == null)) { return(null); } XmlSchemaElement element2 = this.FindDataSetElement(schema, schemas); if (element2 == null) { return(null); } string str3 = this.ImportSchemaType(element2.SchemaType, element2, schemas, importer, compileUnit, mainNamespace, options, codeProvider); if (str2 == null) { return(str3); } return(CodeGenHelper.GetTypeName(codeProvider, str3, str2)); } } } if ((type2.Particle is XmlSchemaSequence) || (type2.Particle is XmlSchemaAll)) { XmlSchemaObjectCollection objects2 = ((XmlSchemaGroupBase)type2.Particle).Items; if (objects2.Count == 1) { if (objects2[0] is XmlSchemaAny) { XmlSchemaAny any3 = (XmlSchemaAny)objects2[0]; if (any3.Namespace == null) { return(null); } if (any3.Namespace.IndexOf('#') >= 0) { return(null); } if (any3.Namespace.IndexOf(' ') >= 0) { return(null); } IList list2 = schemas.GetSchemas(any3.Namespace); if (list2.Count != 1) { return(null); } XmlSchema schema2 = list2[0] as XmlSchema; if (schema2 == null) { return(null); } if (schema2.Id == null) { return(null); } XmlSchemaElement element3 = this.FindDataSetElement(schema2, schemas); if (element3 != null) { return(this.ImportSchemaType(element3.SchemaType, element3, schemas, importer, compileUnit, mainNamespace, options, codeProvider)); } } return(null); } } } } return(null); }
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); } } } } } }