예제 #1
0
        private void Prepare()
        {
            // todo: bad design - make service
            var model = ModelsCachedContainer.GetRawModel(_dbContextType, _logger);

            UsedDbContextModel = model != null;
            Log(nameof(Prepare),
                UsedDbContextModel
                    ? "Use dbContext model"
                    : "Don't use dbContext model");
            var tableNames = GetTableNamesFromModel(model, _logger);

            DefaultSchema = DefaultSchemaUpdater.GetDefaultSchema(_dbContextType, model, _logger);
            foreach (var property in _dbContextType.GetProperties())
            {
                var propertyType = property.PropertyType;
                if (!propertyType.GetTypeInfo().IsGenericType)
                {
                    continue;
                }
                if (propertyType.GetGenericTypeDefinition() != typeof(DbSet <>))
                {
                    continue;
                }
                var entityType = propertyType.GetGenericArguments()[0];
                var entity     = CreateDbSetWrapper(entityType, property.Name, tableNames);
                var key        = new FullTableName(entity.TableName, entity.Schema);
                _dbSets[key] = entity;
            }
        }
 private static EfModelWrapper GetModel(Type dbContextType, bool raw)
 {
     try
     {
         var sandboxed = new ModelsCachedContainer
         {
             DbContextType = dbContextType,
             Raw           = raw
         };
         return(sandboxed.GetModel());
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.Message);
         throw;
     }
 }
예제 #3
0
        private void Prepare()
        {
            // todo: bad design - make service
            var model = ModelsCachedContainer.GetRawModel(_dbContextType, _logger);

            UsedDbContextModel = model != null;
            Log(nameof(Prepare),
                UsedDbContextModel
                    ? "Use dbContext model"
                    : "Don't use dbContext model");
            DefaultSchema = DefaultSchemaUpdater.GetDefaultSchema(_dbContextType, model, _logger);
            var rawTableNames = GetTableNamesFromModel(model, _logger);

            DefaultIsUnicodeText = DefaultSchemaUpdater.GetDefaultIsUnicodeText(_dbContextType, _logger);
            foreach (var i in UsedShamanOptions.Services.OfType <IModelPrepareService>())
            {
                i.UpdateModel(this, _dbContextType, _logger);
            }

/*
 *          foreach (var property in _dbContextType.GetProperties())
 *          {
 *              var propertyType = property.PropertyType;
 *              if (!propertyType.GetTypeInfo().IsGenericType) continue;
 *              if (propertyType.GetGenericTypeDefinition() != typeof(DbSet<>)) continue;
 *              var entityType = propertyType.GetGenericArguments()[0];
 *
 *              var fullTableName = GetTableName(entityType, property.Name, rawTableNames, DefaultSchema);
 *              var entity     = CreateDbSetWrapper(entityType, fullTableName);
 *              var key = new FullTableName(entity.TableName, entity.Schema);
 *              key = key.WithDefaultSchema(DefaultSchema);
 *              _dbSets[key] = entity;
 *              _dbSetsWithoutModifications[fullTableName] = entity;
 *          }
 */
            foreach (var aa in GetEntityTypes(_dbContextType))
            {
                var fullTableName = GetTableName(aa.EntityType, aa.Property.Name, rawTableNames, DefaultSchema);
                var entity        = CreateDbSetWrapper(aa.EntityType, fullTableName);
                var key           = new FullTableName(entity.TableName, entity.Schema);
                key          = key.WithDefaultSchema(DefaultSchema);
                _dbSets[key] = entity;
            }
        }
예제 #4
0
        private static EfModelWrapper GetModel(Type dbContextType, bool raw, IShamanLogger logger)
        {
            Action <string> log = message => logger.Log(typeof(ModelsCachedContainer), nameof(GetModelInternal),
                                                        message);

            try
            {
                var instance = new ModelsCachedContainer
                {
                    DbContextType = dbContextType,
                    Raw           = raw,
                    Logger        = logger
                };
                return(instance.GetModelInternal());
            }
            catch (Exception e)
            {
                log("Exception " + e.Message);
                throw;
            }
        }
        private static EfModelWrapper GetModel(Type dbContextType, bool raw, IShamanLogger logger)
        {
            Action <string> log = message => logger.Log(typeof(ModelsCachedContainer), nameof(GetModelInternal),
                                                        message);

            try
            {
                var instance = new ModelsCachedContainer
                {
                    DbContextType = dbContextType,
                    Raw           = raw,
                    Logger        = logger
                };
                return(instance.GetModelInternal());
            }
            catch (Exception e)
            {
                logger.LogException(Guid.Parse("{F0BA1A53-86D9-430D-99A7-4D5792C593EF}"), e);
                log("Exception " + e.Message);
                throw;
            }
        }