Zend certified PHP/Magento developer

Getting TypeError when try to create an inner join using a custom product attribute

Any idea on below error? I’m getting this error when trying to filter the product collection with custom product attribute. i’m using Magento 2.4.1

TypeError: Argument 1 passed to MagentoCatalogModelResourceModelProductCollection::getEntityPkName() must be an instance of MagentoEavModelEntityAbstractEntity, instance of MagentoCatalogModelResourceModelProductFlat given, called in /data/web/magento2/vendor/magento/module-eav/Model/Entity/Collection/AbstractCollection.php on line 1395

$collection->addAttributeToFilter(
[
[
‘attribute’ => ‘name’,
‘like’ => ‘%’.$productname.’%’
],
[
‘attribute’ => ‘sku’,
‘like’ => $productname.’%’
],
[
‘attribute’ => ‘my_custom_attribute’,
‘like’ => ‘%’ . $productname . ‘%’
]
]
);