public EntityConfiguration Configure <TEntity>(Action <IRootEntityConfigurator <TEntity> > options)
        {
            if (_configuration.Mappings.ContainsKey(typeof(TEntity)))
            {
                throw new InvalidOperationException("Entity has already been configured.");
            }

            var entityType = _context.Model.FindEntityType(typeof(TEntity));

            if (entityType == null)
            {
                throw new InvalidOperationException("Entity is not part of DbContext.");
            }

            // Execute the entity configuration.
            var configurator = new EntityConfigurator <TContext, TEntity>(this, _context, entityType);

            options(configurator);

            // Add the entity configuration to the configuration.
            _configuration.Add(configurator);

            // Return the configuration.
            return(configurator.Configuration);
        }
Example #2
0
 public void Add <TEntity>(EntityConfigurator <TContext, TEntity> configurator)
 {
     _configurations.Add(typeof(TEntity), configurator.Configuration);
 }