Try this:
foreach (EntityTypeInfo eti in EntityTypeInfo.GetAllDynamicTypes()) {
if (typeof(DynamicEntity).IsAssignableFrom(eti.EntityType) && (eti.DataSourceExtension == this.mPm1.DataSourceExtension)) {
this.mPm1.RemoveEntities(eti.EntityType, DataRowState.Unchanged);
}
}
The EntityTypeInfoGetAllDynamicTypes method is unfortunately misnamed – it will return all known entity types, and also returns everything for all known data source extensions. (I might enter a defect report to fix this.) Anyway, if you then filter out actual dynamic types for your data source extension, you can then do the RemoveEntities call. Note that the dynamic entity type still exists, and its entity table is still in the PM. Also note that removing entities with this overload, even if dynamic, causes the query cache to be cleared. If this behavior isn’t wanted, you’d have to first retrieve the entities, and then use the RemoveEntities(list, bool) overload.