简单但不是 100% 保证的方法
在 EzApi 扩展的基础组件上调用 ReinitializeMetaData:
dc.Comp.ReinitializeMetaData();
这并不总是尊重 EzAPI 的一些自定义和逻辑检查,因此请仔细测试。但是,对于大多数香草组件,这应该可以正常工作。
100% 有保证的方法,但需要一种用于识别要忽略的列的策略
您可以使用 EzApi 的 SetUsageType 包装方法将这些 VirtualInputColumns 的 UsageType 属性设置为枚举值 DTSUsageType.UT_IGNORED。
但!您必须在修改完组件的任何其他元数据(附加其他组件、添加新的输入或输出列等)后执行此操作,因为这些都会触发ReinitializeMetaData
组件上的方法,该方法会自动设置(或重置VirtualInputColumn
)所有 UT_IGNOREDUsageType
到UT_READONLY
.
所以一些示例代码:
// define EzSourceComponent with SourceColumnToIgnore output column, SomeConnection for destination
EzDerivedColumn dc = new EzDerivedColumn(this);
dc.AttachTo(EzSourceComponent);
dc.Name = "Errors, Go Away";
dc.InsertOutputColumn("NewDerivedColumn");
dc.Expression["NewDerivedColumn"] = "I was inserted!";
// Right here, UsageType is UT_READONLY
Console.WriteLine(dc.VirtualInputCol("SourceColumnToIgnore").UsageType.ToString());
EzOleDbDestination d = new EzOleDbDestination(f);
d.Name = "Destination";
d.Connection = SomeConnection;
d.Table = "dbo.DestinationTable";
d.AccessMode = AccessMode.AM_OPENROWSET_FASTLOAD;
d.AttachTo(dc);
// Now we can set usage type on columns to remove them from the available inputs.
// Note the false boolean at the end.
// That's required to not trigger ReinitializeMetadata for usage type changes.
dc.SetUsageType(0, "SourceColumnToIgnore", DTSUsageType.UT_IGNORED, false);
// Now UsageType is UT_IGNORED and if you saved the package and viewed it,
// you'll see this column has been removed from the available input columns
// ... and the warning for it has gone away!
Console.WriteLine(dc.VirtualInputCol("SourceColumnToIgnore").UsageType.ToString());