示例#1
0
        private IList <EdmSchemaError> GenerateCodeFor1_1Schema(string sourceEdmSchemaFilePath, LazyTextWriterCreator textWriter, IEnumerable <string> additionalEdmSchemaFilePaths)
        {
            EntityClassGenerator generator = new EntityClassGenerator(_languageOption);
            string target        = textWriter.TargetFilePath;
            bool   cleanUpTarget = false;

            try
            {
                if (textWriter.IsUserSuppliedTextWriter)
                {
                    cleanUpTarget = true;
                    target        = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
                }

                IList <EdmSchemaError> errors = generator.GenerateCode(sourceEdmSchemaFilePath, target, additionalEdmSchemaFilePaths != null ? additionalEdmSchemaFilePaths : Enumerable.Empty <string>());

                if (textWriter.IsUserSuppliedTextWriter && !errors.Any(e => e.Severity == EdmSchemaErrorSeverity.Error))
                {
                    textWriter.GetOrCreateTextWriter().Write(File.ReadAllText(target));
                }

                return(errors);
            }
            finally
            {
                if (cleanUpTarget && target != null && File.Exists(target))
                {
                    File.Delete(target);
                }
            }
        }
示例#2
0
        public static bool CodeGen(String edmxFile, LanguageOption languageOption, out String codeOut, out List<Object> errors)
        {
            codeOut = String.Empty;

            XDocument xdoc = XDocument.Load(edmxFile);
            XElement c = GetCsdlFromEdmx(xdoc);
            Version v = _namespaceManager.GetVersionFromEDMXDocument(xdoc);

            StringWriter sw = new StringWriter();

            errors = new List<Object>();

            //
            // code-gen uses different classes for V1 and V2 of the EF
            //
            if (v == EntityFrameworkVersions.Version1)
            {
                // generate code
                EntityClassGenerator codeGen = new EntityClassGenerator(languageOption);
                errors = codeGen.GenerateCode(c.CreateReader(), sw) as List<Object>;
            }
            else if (v == EntityFrameworkVersions.Version2)
            {
                EntityCodeGenerator codeGen = new EntityCodeGenerator(languageOption);
                errors = codeGen.GenerateCode(c.CreateReader(), sw) as List<Object>;
            }

            else if (v == EntityFrameworkVersions.Version3)
            {
                EntityCodeGenerator codeGen = new EntityCodeGenerator(languageOption);
                errors = codeGen.GenerateCode(c.CreateReader(), sw) as List<Object>;
            }

            // output errors
            if (errors != null)
                return true;

            codeOut = sw.ToString();
            return false;
        }
示例#3
0
 /// <summary>
 ///     This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.
 /// </summary>
 /// <param name="sourceEdmSchema">This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.</param>
 /// <param name="target">This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.</param>
 /// <returns>This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.</returns>
 public override IList <EdmSchemaError> GenerateCode(XmlReader sourceEdmSchema, TextWriter target)
 {
     return(FromLegacySchemaErrors(_entityClassGenerator.GenerateCode(sourceEdmSchema, target)));
 }
        private IList<EdmSchemaError> GenerateCodeFor1_1Schema(string sourceEdmSchemaFilePath, LazyTextWriterCreator textWriter, IEnumerable<string> additionalEdmSchemaFilePaths)
        {
            EntityClassGenerator generator = new EntityClassGenerator(_languageOption);
            string target = textWriter.TargetFilePath;
            bool cleanUpTarget = false;
            try
            {
                if (textWriter.IsUserSuppliedTextWriter)
                {
                    cleanUpTarget = true;
                    target = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());

                }

                IList<EdmSchemaError> errors = generator.GenerateCode(sourceEdmSchemaFilePath, target, additionalEdmSchemaFilePaths != null ? additionalEdmSchemaFilePaths : Enumerable.Empty<string>());

                if (textWriter.IsUserSuppliedTextWriter && !errors.Any(e => e.Severity == EdmSchemaErrorSeverity.Error))
                {
                    textWriter.GetOrCreateTextWriter().Write(File.ReadAllText(target));
                }

                return errors;
            }
            finally
            {
                if (cleanUpTarget && target != null && File.Exists(target))
                {
                    File.Delete(target);
                }
            }

        }
示例#5
0
		private static void CodeGen(FileInfo edmxFile, LanguageOption languageOption)
		{
			XDocument xdoc = XDocument.Load(edmxFile.FullName);
			Version v = _namespaceManager.GetVersionFromEDMXDocument(xdoc);
			XElement c = GetCsdlFromEdmx(xdoc);

			StringWriter sw = new StringWriter();
			IList<EdmSchemaError> errors = null;

			//
			// code-gen uses different classes for V1 and V2 of the EF 
			//
			if (v == EntityFrameworkVersions.Version1)
			{
				// generate code
				EntityClassGenerator codeGen = new EntityClassGenerator(languageOption);
				errors = codeGen.GenerateCode(c.CreateReader(), sw);
			}
			else if (v == EntityFrameworkVersions.Version2)
			{
				EntityCodeGenerator codeGen = new EntityCodeGenerator(languageOption);
				errors = codeGen.GenerateCode(c.CreateReader(), sw);
			}

			// write out code-file
			string outputFileName = GetFileNameWithNewExtension(edmxFile,
					GetFileExtensionForLanguageOption(languageOption));
			File.WriteAllText(outputFileName, sw.ToString());

			// output errors
			WriteErrors(errors);
		}
示例#6
0
		private static void CodeGen(FileInfo edmxFile, LanguageOption languageOption)
		{
			XElement c = GetCsdlFromEdmx(XDocument.Load(edmxFile.FullName));

			// generate code
			StringWriter sw = new StringWriter();
			EntityClassGenerator codeGen = new EntityClassGenerator(languageOption);
			IList<EdmSchemaError> errors = codeGen.GenerateCode(c.CreateReader(), sw);

			// write out code-file
			string outputFileName = GetFileNameWithNewExtension(edmxFile,
				 GetFileExtensionForLanguageOption(languageOption));
			File.WriteAllText(outputFileName, sw.ToString());

			// output errors
			WriteErrors(errors);
		}