예제 #1
0
        public override void GenerateCode(IFunctionBuilder functionBuilder)
        {
            var generator = new DbBulkCopy_Gen();

            generator.Session = new Dictionary <string, object>();
            generator.Session.Add("FunctionContextProperty", functionBuilder.ContextParamName);
            generator.Session.Add("ConnectionType", FunctionData.Properties[DbShared.ConnectionTypePropertyName].GetValue <ConnectionTypeSelection>().ToConnectionType());
            generator.Session.Add("ConnectionStringProperty", functionBuilder.GetParamName(DbShared.ConnectionStringPropertyName));
            generator.Session.Add("Timeout", FunctionData.Properties[DbBulkCopyShared.TimeoutPropertyName].GetValue <int>());
            generator.Session.Add("BatchSize", FunctionData.Properties[DbBulkCopyShared.BatchSizePropertyName].GetValue <int>());
            generator.Session.Add("TableName", FunctionData.Properties[DbBulkCopyShared.TableNamePropertyName].GetValue <string>());
            var columns = FunctionData.Properties[DbBulkCopyShared.ColumnsPropertyName].GetValue <DatabaseModel.Columns>();

            generator.Session.Add("ColumnNames", columns.Select(c => c.Name).ToArray());
            generator.Session.Add("ColumnPropertyNames", columns.Select(c => DbBulkCopyShared.GetPropertyName(c.Name)).ToArray());
            generator.Session.Add("ColumnDataTypes", columns.Select(c => c.DataType).ToArray());
            generator.Session.Add("ExecutionPathOutputName", functionBuilder.ExecutionPathOutParamName);
            generator.Session.Add("ExecutionPathName", DbBulkCopyShared.ExecutionPathName);

            generator.Initialize();
            functionBuilder.AddCode(generator.TransformText());
            functionBuilder.AddAssemblyReference(typeof(Loader));
            functionBuilder.AddAssemblyReference(typeof(RuntimeBinderException));
        }
예제 #2
0
        private void RefreshExecutionPath()
        {
            var columns = Properties[DbBulkCopyShared.ColumnsPropertyName].GetValue <DatabaseModel.Columns>();

            if (columns.Any())
            {
                TypeReference outputTypeReference = new DynamicCompiledTypeReference(typeof(Loader), _ =>
                {
                    var rowTypeBuilder = new TypeBuilder();
                    foreach (var nextColumn in columns)
                    {
                        Type systemType             = nextColumn.DataType.GetSystemType();
                        bool isNullableType         = systemType.IsClass;
                        ITypeReference propertyType = isNullableType ? systemType.MapType() : TypeReference.Create(typeof(Nullable <>).MakeGenericType(systemType));

                        rowTypeBuilder.AddProperty(
                            DbBulkCopyShared.GetPropertyName(nextColumn.Name),
                            propertyType);
                    }
                    return(rowTypeBuilder.CreateTypeReference());
                });

                if (ExecutionPaths.Any())
                {
                    ExecutionPaths[DbBulkCopyShared.ExecutionPathName].Output = outputTypeReference;
                }
                else
                {
                    ExecutionPaths.Add(DbBulkCopyShared.ExecutionPathName, DbBulkCopyShared.ExecutionPathName, outputTypeReference, IterationHint.Once);
                }
            }
            else if (ExecutionPaths.Any())
            {
                ExecutionPaths.Clear();
            }
        }