예제 #1
0
        public static XDocument CreateEDMXFromIDatabase(IDatabase database, string modelNamespace, string objectContextNamespace, string objectContextName)
        {
            XDocument ssdlXDocument = GetSSDLXML(database, modelNamespace);

            string ssdlTempFilename = IO.IO.GetTempFilenameWithExtension("ssdl");

            ssdlXDocument.Save(ssdlTempFilename);

            FileInfo fileInfo     = new FileInfo(ssdlTempFilename);
            string   filenameRump = Path.GetTempPath() + fileInfo.Name.Replace(fileInfo.Extension, string.Empty);

            string edmGenPath = RuntimeEnvironment.GetRuntimeDirectory() + "\\EdmGen.exe";

            Process          process          = new Process();
            ProcessStartInfo processStartInfo = new ProcessStartInfo();

            processStartInfo.WorkingDirectory = Path.GetTempPath();
            processStartInfo.FileName         = edmGenPath;
            processStartInfo.Arguments        = string.Format(@"/mode:FromSSDLGeneration /inssdl:""{0}.ssdl"" /outcsdl:""{0}.csdl"" /outmsl:""{0}.msl"" /outobjectlayer:""{1}.Designer.cs"" /outviews:""{1}.Views.cs"" /Namespace:{2} /EntityContainer:{1}",
                                                              filenameRump, objectContextName, objectContextNamespace);
            processStartInfo.UseShellExecute        = false;
            processStartInfo.ErrorDialog            = false;
            processStartInfo.RedirectStandardOutput = true;
            processStartInfo.RedirectStandardError  = true;
            process.StartInfo = processStartInfo;
            process.Start();
            string outputMessage = process.StandardOutput.ReadToEnd();

            process.WaitForExit();

            if (process.ExitCode != 0)
            {
                throw new ObjectModelConverterException(string.Format("An error occured during generating the EDMX file from \"{0}.ssdl\".", filenameRump),
                                                        outputMessage, ObjectModelConverterExceptionEnum.EDM);
            }

            XDocument csdlXDocument = XDocument.Load(filenameRump + ".csdl");
            XDocument mslXDocument  = XDocument.Load(filenameRump + ".msl");

            mslXDocument = MSLIO.GenerateTypeMapping(mslXDocument);

            return(EDMXIO.WriteXDocument(ssdlXDocument, csdlXDocument, mslXDocument));
        }
 public override void Save(OpenedFile file, Stream stream)
 {
     EDMXIO.WriteXDocument(_edmView).Save(stream);
 }