Esempio n. 1
0
		private static void ModelGen(
				string connectionString, string provider, string modelName, Version version, bool includeForeignKeys)
		{
			IList<EdmSchemaError> ssdlErrors = null;
			IList<EdmSchemaError> csdlAndMslErrors = null;

			// generate the SSDL
			string ssdlNamespace = modelName + "Model.Store";
			EntityStoreSchemaGenerator essg =
					new EntityStoreSchemaGenerator(
							provider, connectionString, ssdlNamespace);
			essg.GenerateForeignKeyProperties = includeForeignKeys;

			ssdlErrors = essg.GenerateStoreMetadata(new List<EntityStoreSchemaFilterEntry>(), version);

			// detect if there are errors or only warnings from ssdl generation
			bool hasSsdlErrors = false;
			bool hasSsdlWarnings = false;
			if (ssdlErrors != null)
			{
				foreach (EdmSchemaError e in ssdlErrors)
				{
					if (e.Severity == EdmSchemaErrorSeverity.Error)
					{
						hasSsdlErrors = true;
					}
					else if (e.Severity == EdmSchemaErrorSeverity.Warning)
					{
						hasSsdlWarnings = true;
					}
				}
			}

			// write out errors & warnings
			if (hasSsdlErrors && hasSsdlWarnings)
			{
				System.Console.WriteLine("Errors occurred during generation:");
				WriteErrors(ssdlErrors);
			}

			// if there were errors abort.  Continue if there were only warnings
			if (hasSsdlErrors)
			{
				return;
			}

			// write the SSDL to a string
			StringWriter ssdl = new StringWriter();
			XmlWriter ssdlxw = XmlWriter.Create(ssdl);
			essg.WriteStoreSchema(ssdlxw);
			ssdlxw.Flush();

			// generate the CSDL
			string csdlNamespace = modelName + "Model";
			string csdlEntityContainerName = modelName + "Entities";
			EntityModelSchemaGenerator emsg =
					new EntityModelSchemaGenerator(
							essg.EntityContainer, csdlNamespace, csdlEntityContainerName);
			emsg.GenerateForeignKeyProperties = includeForeignKeys;
			csdlAndMslErrors = emsg.GenerateMetadata(version);


			// detect if there are errors or only warnings from csdl/msl generation
			bool hasCsdlErrors = false;
			bool hasCsdlWarnings = false;
			if (csdlAndMslErrors != null)
			{
				foreach (EdmSchemaError e in csdlAndMslErrors)
				{
					if (e.Severity == EdmSchemaErrorSeverity.Error)
					{
						hasCsdlErrors = true;
					}
					else if (e.Severity == EdmSchemaErrorSeverity.Warning)
					{
						hasCsdlWarnings = true;
					}
				}
			}

			// write out errors & warnings
			if (hasCsdlErrors || hasCsdlWarnings)
			{
				System.Console.WriteLine("Errors occurred during generation:");
				WriteErrors(csdlAndMslErrors);
			}

			// if there were errors, abort.  Don't abort if there were only warnigns.  
			if (hasCsdlErrors)
			{
				return;
			}

			// write CSDL to a string
			StringWriter csdl = new StringWriter();
			XmlWriter csdlxw = XmlWriter.Create(csdl);
			emsg.WriteModelSchema(csdlxw);
			csdlxw.Flush();

			// write MSL to a string
			StringWriter msl = new StringWriter();
			XmlWriter mslxw = XmlWriter.Create(msl);
			emsg.WriteStorageMapping(mslxw);
			mslxw.Flush();

			// write csdl, ssdl & msl to the EDMX file
			ToEdmx(
					csdl.ToString(), ssdl.ToString(), msl.ToString(), new FileInfo(
							modelName + ".edmx"));
		}
Esempio n. 2
0
        // End Added ErikEJ

        #region the functions that actually do the interesting things

        private static void ModelGen(
            string connectionString, string provider, string modelName, Version version, bool includeForeignKeys, bool pluralize, List<string> tables)
        {
            IList<EdmSchemaError> ssdlErrors = null;
            IList<EdmSchemaError> csdlAndMslErrors = null;

            // generate the SSDL
            string ssdlNamespace = modelName + "Model.Store";
            EntityStoreSchemaGenerator essg =
                new EntityStoreSchemaGenerator(
                    provider, connectionString, ssdlNamespace);
            essg.GenerateForeignKeyProperties = includeForeignKeys;

            //ErikEJ Filter selected tables
            var filters = new List<EntityStoreSchemaFilterEntry>();
            foreach (var table in tables)
            {
                var entry = new EntityStoreSchemaFilterEntry(null, null, table);
                filters.Add(entry);
            }
            ssdlErrors = essg.GenerateStoreMetadata(filters, version);

            // detect if there are errors or only warnings from ssdl generation
            bool hasSsdlErrors = false;
            bool hasSsdlWarnings = false;
            if (ssdlErrors != null)
            {
                foreach (EdmSchemaError e in ssdlErrors)
                {
                    if (e.Severity == EdmSchemaErrorSeverity.Error)
                    {
                        hasSsdlErrors = true;
                    }
                    else if (e.Severity == EdmSchemaErrorSeverity.Warning)
                    {
                        hasSsdlWarnings = true;
                    }
                }
            }

            // write out errors & warnings
            if (hasSsdlErrors && hasSsdlWarnings)
            {
                //System.Console.WriteLine("Errors occurred during generation:");
                WriteErrors(ssdlErrors);
            }

            // if there were errors abort.  Continue if there were only warnings
            if (hasSsdlErrors)
            {
                return;
            }

            // write the SSDL to a string
            using (StringWriter ssdl = new StringWriter())
            {
                XmlWriter ssdlxw = XmlWriter.Create(ssdl);
                essg.WriteStoreSchema(ssdlxw);
                ssdlxw.Flush();

                // generate the CSDL
                string csdlNamespace = modelName + "Model";
                string csdlEntityContainerName = modelName + "Entities";
                EntityModelSchemaGenerator emsg =
                    new EntityModelSchemaGenerator(
                        essg.EntityContainer, csdlNamespace, csdlEntityContainerName);
                emsg.GenerateForeignKeyProperties = includeForeignKeys;

                // Begin Added ErikEJ
                if (pluralize)
                    emsg.PluralizationService = System.Data.Entity.Design.PluralizationServices.PluralizationService.CreateService(new System.Globalization.CultureInfo("en-US"));
                // End Added ErikEJ
                csdlAndMslErrors = emsg.GenerateMetadata(version);


                // detect if there are errors or only warnings from csdl/msl generation
                bool hasCsdlErrors = false;
                bool hasCsdlWarnings = false;
                if (csdlAndMslErrors != null)
                {
                    foreach (EdmSchemaError e in csdlAndMslErrors)
                    {
                        if (e.Severity == EdmSchemaErrorSeverity.Error)
                        {
                            hasCsdlErrors = true;
                        }
                        else if (e.Severity == EdmSchemaErrorSeverity.Warning)
                        {
                            hasCsdlWarnings = true;
                        }
                    }
                }

                // write out errors & warnings
                if (hasCsdlErrors || hasCsdlWarnings)
                {
                    //System.Console.WriteLine("Errors occurred during generation:");
                    WriteErrors(csdlAndMslErrors);
                }

                // if there were errors, abort.  Don't abort if there were only warnigns.  
                if (hasCsdlErrors)
                {
                    return;
                }

                // write CSDL to a string
                using (StringWriter csdl = new StringWriter())
                {
                    XmlWriter csdlxw = XmlWriter.Create(csdl);
                    emsg.WriteModelSchema(csdlxw);
                    csdlxw.Flush();

                    // write MSL to a string
                    using (StringWriter msl = new StringWriter())
                    {
                        XmlWriter mslxw = XmlWriter.Create(msl);
                        emsg.WriteStorageMapping(mslxw);
                        mslxw.Flush();

                        // write csdl, ssdl & msl to the EDMX file
                        ToEdmx(
                            csdl.ToString(), ssdl.ToString(), msl.ToString(), new FileInfo(
                                modelName + ".edmx"), includeForeignKeys, pluralize);
                    }
                }
            }
        }
Esempio n. 3
0
		private static void ModelGen(
			 string connectionString, string provider, string modelName)
		{
			IList<EdmSchemaError> ssdlErrors = null;
			IList<EdmSchemaError> csdlAndMslErrors = null;

			// generate the SSDL
			string ssdlNamespace = modelName + "Model.Store";
			EntityStoreSchemaGenerator essg =
				 new EntityStoreSchemaGenerator(
						provider, connectionString, ssdlNamespace);
			ssdlErrors = essg.GenerateStoreMetadata();

			// write out errors
			if ((ssdlErrors != null && ssdlErrors.Count > 0))
			{
				System.Console.WriteLine("Errors occurred during generation:");
				WriteErrors(ssdlErrors);
				return;
			}

			// write the SSDL to a string
			StringWriter ssdl = new StringWriter();
			XmlWriter ssdlxw = XmlWriter.Create(ssdl);
			essg.WriteStoreSchema(ssdlxw);
			ssdlxw.Flush();

			// generate the CSDL
			string csdlNamespace = modelName + "Model";
			string csdlEntityContainerName = modelName + "Entities";
			EntityModelSchemaGenerator emsg =
				 new EntityModelSchemaGenerator(
						essg.EntityContainer, csdlNamespace, csdlEntityContainerName);
			csdlAndMslErrors = emsg.GenerateMetadata();

			// write out errors
			if (csdlAndMslErrors != null && csdlAndMslErrors.Count > 0)
			{
				System.Console.WriteLine("Errors occurred during generation:");
				WriteErrors(csdlAndMslErrors);
				return;
			}

			// write CSDL to a string
			StringWriter csdl = new StringWriter();
			XmlWriter csdlxw = XmlWriter.Create(csdl);
			emsg.WriteModelSchema(csdlxw);
			csdlxw.Flush();

			// write MSL to a string
			StringWriter msl = new StringWriter();
			XmlWriter mslxw = XmlWriter.Create(msl);
			emsg.WriteStorageMapping(mslxw);
			mslxw.Flush();

			// write csdl, ssdl & msl to the EDMX file
			ToEdmx(
				 csdl.ToString(), ssdl.ToString(), msl.ToString(), new FileInfo(
						modelName + ".edmx"));
		}
Esempio n. 4
0
        public static bool ModelGen(string connectionString, string provider, string modelName, Version version, bool includeForeignKeys, out String modelOut, out List<Object> errors)
        {
            modelOut = String.Empty;
            errors = new List<Object>();
            IList<EdmSchemaError> ssdlErrors = null;
            IList<EdmSchemaError> csdlAndMslErrors = null;

            // generate the SSDL
            string ssdlNamespace = modelName + "Model.Store";
            EntityStoreSchemaGenerator essg = new EntityStoreSchemaGenerator(provider, connectionString, ssdlNamespace);
            essg.GenerateForeignKeyProperties = includeForeignKeys;

            ssdlErrors = essg.GenerateStoreMetadata(new List<EntityStoreSchemaFilterEntry>(), version);

            // detect if there are errors or only warnings from ssdl generation
            bool hasSsdlErrors = false;
            bool hasSsdlWarnings = false;
            if (ssdlErrors != null)
            {
                foreach (EdmSchemaError e in ssdlErrors)
                {
                    if (e.Severity == EdmSchemaErrorSeverity.Error)
                    {
                        hasSsdlErrors = true;
                    }
                    else if (e.Severity == EdmSchemaErrorSeverity.Warning)
                    {
                        hasSsdlWarnings = true;
                    }
                }
            }

            // write out errors & warnings
            if (hasSsdlErrors && hasSsdlWarnings)
            {
                errors.AddRange(ssdlErrors);
            }

            // if there were errors abort.  Continue if there were only warnings
            if (hasSsdlErrors)
            {
                return true;
            }

            // write the SSDL to a string
            StringWriter ssdl = new StringWriter();
            XmlWriter ssdlxw = XmlWriter.Create(ssdl);
            essg.WriteStoreSchema(ssdlxw);
            ssdlxw.Flush();

            // generate the CSDL
            string csdlNamespace = modelName + "Model";
            string csdlEntityContainerName = modelName + "Entities";
            EntityModelSchemaGenerator emsg = new EntityModelSchemaGenerator(essg.EntityContainer, csdlNamespace, csdlEntityContainerName);
            emsg.GenerateForeignKeyProperties = includeForeignKeys;
            csdlAndMslErrors = emsg.GenerateMetadata(version);

            // detect if there are errors or only warnings from csdl/msl generation
            bool hasCsdlErrors = false;
            bool hasCsdlWarnings = false;
            if (csdlAndMslErrors != null)
            {
                foreach (EdmSchemaError e in csdlAndMslErrors)
                {
                    if (e.Severity == EdmSchemaErrorSeverity.Error)
                    {
                        hasCsdlErrors = true;
                    }
                    else if (e.Severity == EdmSchemaErrorSeverity.Warning)
                    {
                        hasCsdlWarnings = true;
                    }
                }
            }

            // write out errors & warnings
            if (hasCsdlErrors || hasCsdlWarnings)
            {
                errors.AddRange(csdlAndMslErrors);
            }

            // if there were errors, abort.  Don't abort if there were only warnigns.
            if (hasCsdlErrors)
            {
                return true;
            }

            // write CSDL to a string
            StringWriter csdl = new StringWriter();
            XmlWriter csdlxw = XmlWriter.Create(csdl);
            emsg.WriteModelSchema(csdlxw);
            csdlxw.Flush();

            // write MSL to a string
            StringWriter msl = new StringWriter();
            XmlWriter mslxw = XmlWriter.Create(msl);
            emsg.WriteStorageMapping(mslxw);
            mslxw.Flush();

            // write csdl, ssdl & msl to the EDMX file. A default Designer section will be added
            modelOut = ToEdmx(csdl.ToString(), ssdl.ToString(), msl.ToString(), String.Empty);
            return false;
        }