Hello,
I am receiving an error when trying to delete a set of entities directly in the database, without loading them first. I am using LL 2.6, adapter templates, and the PostgreSQL driver.
This delete requires the use of an IN predicate. My first implementation using Linq works fine, but I would like to eliminate the need to read the IN set into memory before composing the Delete predicate:
var query =
(from archivedStoreTemplate in metaData.MerchantArchivedStoreTemplates
where archivedStoreTemplate.MerchantStoreId == merchantStoreTemplate.MerchantStoreId
orderby archivedStoreTemplate.CreatedAt
select archivedStoreTemplate.Id).Take(countArchivedTemplates - MaxArchiveCount);
dataAccessAdapter.DeleteEntitiesDirectly(typeof(MerchantArchivedStoreTemplatesEntity),
new RelationPredicateBucket(new FieldCompareRangePredicate(MerchantArchivedStoreTemplatesFields.Id, null,
query.ToArray())));
I am reproducing this query:
DELETE FROM
merchant_archived_store_templates
WHERE
id IN (SELECT id FROM merchant_archived_store_templates
WHERE merchant_store_id = merchant_store_id_in
ORDER BY created_at ASC LIMIT archive_count - max_archive_count_in);
Using the native LLBLGen api, I tried forming a FieldCompareSet predicate:
IPredicate deleteFilter = new FieldCompareSetPredicate(
MerchantArchivedStoreTemplatesFields.Id, null, MerchantArchivedStoreTemplatesFields.Id, null, SetOperator.In,
(MerchantArchivedStoreTemplatesFields.MerchantStoreId == merchantStoreTemplate.MerchantStoreId), null, null,
5, new SortExpression(MerchantArchivedStoreTemplatesFields.Id | SortOperator.Ascending));
dataAccessAdapter.DeleteEntitiesDirectly(typeof(MerchantArchivedStoreTemplatesEntity), new RelationPredicateBucket(deleteFilter));
This is resulting in the following error and I can't figure out why?
{"Object reference not set to an instance of an object."}
[System.NullReferenceException]: {"Object reference not set to an instance of an object."}
Data: {System.Collections.ListDictionaryInternal}
HelpLink: null
InnerException: null
Message: "Object reference not set to an instance of an object."
Source: "SD.LLBLGen.Pro.DQE.PostgreSql.NET20"
StackTrace: " at SD.LLBLGen.Pro.DQE.PostgreSql.PostgreSqlSpecificCreator.CreateFieldName(IEntityFieldCore fieldCore, IFieldPersistenceInfo persistenceInfo, String fieldName, String objectAlias, Int32& uniqueMarker, Boolean applyAggregateFunction)\r\n
at SD.LLBLGen.Pro.ORMSupportClasses.FieldCompareSetPredicate.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause)\r\n
at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause)\r\n
at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause)\r\n
at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker)\r\n
at SD.LLBLGen.Pro.DQE.PostgreSql.DynamicQueryEngine.CreateSingleTargetDeleteDQ(IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate deleteFilter)\r\n
at SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateDeleteDQ(IFieldPersistenceInfo[] fieldsPersistenceInfo,
IDbConnection connectionToUse, List`1 pkFilters, IPredicate additionalDeleteFilter, IRelationCollection relationsToWalk)\r\n
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.CreateDeleteDQ(IFieldPersistenceInfo[] fieldsPersistenceInfo, List`1 pkFilters, IPredicate additionalDeleteFilter, IRelationCollection relationsToWalk)\r\n
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.DeleteEntitiesDirectly(String entityName, IRelationPredicateBucket filterBucket)\r\n at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.DeleteEntitiesDirectly(Type typeOfEntity, IRelationPredicateBucket filterBucket)\r\n
at OneShop.SecureCart.Business.StoreHelper.SaveMerchantStoreTemplate(MerchantStoreTemplatesEntity merchantStoreTemplate, Boolean makeBackup) in C:\\SVN\\OneShop\\OneShop.SecureCart\\OneShop.SecureCart.Business\\LLBLGenBusinessClasses\\StoreHelper.cs:line 1314"
TargetSite: {System.String CreateFieldName(SD.LLBLGen.Pro.ORMSupportClasses.IEntityFieldCore, SD.LLBLGen.Pro.ORMSupportClasses.IFieldPersistenceInfo, System.String, System.String, Int32 ByRef, Boolean)}
I am hoping someone might be able to put me on the right tracks here?
Thanks.
Can1