/// <summary>Creates a factory defined in the configuration section.</summary>
        public static EntityContextFactory FromConfiguration(string factoryName)
        {
            var configuration = ConfigurationSectionHandler.Default.Factories.Cast <FactoryElement>().First(item => item.Name == factoryName);
            var ontologies    = from element in configuration.Ontologies.Cast <OntologyElement>()
                                select new Ontology(element.Prefix, element.Uri);
            var mappingAssemblies = from element in configuration.MappingAssemblies.Cast <MappingAssemblyElement>() select element.Load();

            var entityContextFactory = new EntityContextFactory()
                                       .WithOntology(new OntologyProviderBase(ontologies))
                                       .WithMetaGraphUri(configuration.MetaGraphUri)
                                       .WithMappings(m =>
            {
                foreach (var mappingAssembly in mappingAssemblies)
                {
                    m.FromAssembly(mappingAssembly);
                }
            });

            entityContextFactory.ThreadSafe   = configuration.ThreadSafe;
            entityContextFactory.TrackChanges = configuration.TrackChanges;
            if (configuration.BaseUris.Default != null)
            {
                entityContextFactory.WithBaseUri(b => b.Default.Is(configuration.BaseUris.Default));
            }

            return(entityContextFactory);
        }
Ejemplo n.º 2
0
 /// <summary>Includes default <see cref="IOntologyProvider" />s in context that will be created.</summary>
 /// <returns>The <see cref="EntityContextFactory" /> </returns>
 public static EntityContextFactory WithDefaultOntologies(this EntityContextFactory factory)
 {
     return(factory.WithOntology(new DefaultOntologiesProvider()));
 }
        /// <summary>
        /// Creates a factory defined in the configuration section.
        /// </summary>
        public static EntityContextFactory FromConfiguration(string factoryName)
        {
            var configuration = ConfigurationSectionHandler.Default.Factories[factoryName];
            var ontologies = from element in configuration.Ontologies.Cast<OntologyElement>()
                             select new Ontology(element.Prefix, element.Uri);
            var mappingAssemblies = from element in configuration.MappingAssemblies.Cast<MappingAssemblyElement>()
                                    select Assembly.Load(element.Assembly);

            var entityContextFactory = new EntityContextFactory().WithOntology(new OntologyProviderBase(ontologies)).WithMappings(m =>
                {
                    foreach (var mappingAssembly in mappingAssemblies)
                    {
                        m.Fluent.FromAssembly(mappingAssembly);
                        m.Attributes.FromAssembly(mappingAssembly);
                    }
                }).WithMetaGraphUri(configuration.MetaGraphUri);
            if (configuration.BaseUris.Default != null)
            {
                entityContextFactory.WithBaseUri(b => b.Default.Is(configuration.BaseUris.Default));
            }

            return entityContextFactory;
        }