示例#1
0
		public void DumpFixedUpScrumDbEdmx()
		{
			DbContextMetadata<ScrumDb> dbContextMetadata;

			using (var db = new ScrumDb())
			{
				dbContextMetadata = new DbContextMetadata<ScrumDb>(db);
			}
			IEdmModel edmModel = dbContextMetadata.EdmModel;

			var xmlSettings = new XmlWriterSettings() { Indent = true };
			IEnumerable<EdmError> writeErrors;
			using (XmlWriter writer = XmlWriter.Create(Console.Out, xmlSettings))
			{
				Microsoft.Data.Edm.Csdl.EdmxWriter.TryWriteEdmx(edmModel, writer, EdmxTarget.OData, out writeErrors);
			}

			if (writeErrors.Any())
			{
				Console.WriteLine();
				Console.WriteLine("EDMX write errors:");
				foreach (var error in writeErrors)
				{
					Console.WriteLine(error.ToString());
				}
			}
		}
示例#2
0
        public void RegisterServices(Container container)
        {
            // Required: How to instantiate the DbContext; and share it amongst objects participating in a single request.
            var webApiRequestLifestyle = new WebApiRequestLifestyle(true);
            var hybridLifestyle = Lifestyle.CreateHybrid(() => webApiRequestLifestyle.GetCurrentScope(container) == null, Lifestyle.Transient, webApiRequestLifestyle);
            container.Register(() =>
                               {
                                   var db = new ScrumDb();
                                   db.AttachDbEnums();
                                   return db;
                               },
                               hybridLifestyle);
            container.RegisterLazy<ScrumDb>();

            // Required: Register global datamodel metadata
            var metadataRegistration = hybridLifestyle.CreateRegistration<DbContextMetadata<ScrumDb>>(container);
            container.AddRegistration(typeof(IContainerMetadata<ScrumDb>), metadataRegistration);
            container.AddRegistration(typeof(IContainerMetadata), metadataRegistration);

            // Query validation settings could be specified here
            //container.RegisterInstance(new ODataValidationSettings
            //{
            //	MaxExpansionDepth = 15,
            //	MaxTop = 200
            //}); //.Named<ODataValidationSettings>("Edit");  TODO: Figure out how to separate ODataValidationSettings for Edit controllers vs ReadOnly controllers
        }
示例#3
0
		public void DumpScrumDbEdmx()
		{
			var xmlSettings = new XmlWriterSettings() { Indent = true };
			using (var db = new ScrumDb())
			using (XmlWriter writer = XmlWriter.Create(Console.Out, xmlSettings))
			{
				EdmxWriter.WriteEdmx(db, writer);
			}
		}
示例#4
0
		public void DumpRoundTrippedEdmx(EdmxTarget edmxTarget)
		{
			IEnumerable<EdmError> writeErrors;

			var sb = new StringBuilder(2048);
			var xmlSettings = new XmlWriterSettings() { Encoding = Encoding.UTF8, Indent = true };
			using (var db = new ScrumDb())
			using (XmlWriter writer = XmlWriter.Create(sb, xmlSettings))
			{
				var edmModel = db.GetEdmModel();
				Microsoft.Data.Edm.Csdl.EdmxWriter.TryWriteEdmx(edmModel, writer, edmxTarget, out writeErrors);
			}
			Console.WriteLine(sb.ToString());

			if (writeErrors.Any())
			{
				Console.WriteLine();
				Console.WriteLine("EDMX write errors:");
				foreach (var error in writeErrors)
				{
					Console.WriteLine(error.ToString());
				}
			}
		}