Migrating from v4.2 to v5.8

Posts   
 
    
simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 26-Aug-2021 12:27:34   

I'm migrating my custom DataAccessAdapter code from v4.2 to v5.8 Here is one I am stuck on where I can't find an obvious replacement method on DataAccessAdapter or QueryCreationManager or DynamicQueryEngine.

This is the line

var selectQuery = queryEngine.CreateSelectDQ(linkTableFields, linkTableFieldPersistenceInfos, GetActiveConnection(), selectFilter, 0, null, null, true, null);

And here is the full containing method just for context - I think the rest will work once the select query is created:

        public int MergeSimpleJoinTableEntriesOnRelationshipDirectly(IEntityRelation relation, int sourceID, int targetID)
        {
            if (relation == null) throw new ArgumentNullException(nameof(relation));
            if (sourceID == targetID) return 0;

            var queryEngine = CreateDynamicQueryEngine();

            var fkField = relation.GetFKEntityFieldCore(0);
            var fkFieldPersistence = QueryCreationManagerAce.GetFieldPersistenceInfoByField(fkField);

            var linkTableEntityType = (EntityType) Enum.Parse(typeof(EntityType), fkField.ContainingObjectName);
            var linkTableEntity = GeneralEntityFactory.Create(linkTableEntityType);
            var linkTableFields = linkTableEntity.Fields.GetAsEntityFieldCoreArray();
            var linkTableFieldPersistenceInfos = QueryCreationManagerAce.GetFieldPersistenceInfosByEntity(linkTableEntity);

            Debug.Assert(linkTableFields.Length == 2);
            Debug.Assert(linkTableFields[0].Name == fkField.Name || linkTableFields[1].Name == fkField.Name);

            // Ensure the Field we will be replacing comes first
            if (linkTableFields[1].Name == fkField.Name)
            {
                (linkTableFields[0], linkTableFields[1]) = (linkTableFields[1], linkTableFields[0]);
                (linkTableFieldPersistenceInfos[0], linkTableFieldPersistenceInfos[1]) = (linkTableFieldPersistenceInfos[1], linkTableFieldPersistenceInfos[0]);
            }

            var sourceFilter = new FieldCompareValuePredicate(fkField, fkFieldPersistence, ComparisonOperator.Equal, sourceID);
            var targetFilter = new FieldCompareValuePredicate(fkField, fkFieldPersistence, ComparisonOperator.Equal, targetID);
            var selectFilter = sourceFilter | targetFilter;

            var selectQuery = queryEngine.CreateSelectDQ(linkTableFields, linkTableFieldPersistenceInfos, GetActiveConnection(), selectFilter, 0, null, null, true, null);

            var dataTable = ExecuteMultiRowDataTableRetrievalQuery(selectQuery, CreateNewPhysicalDataAdapter(), linkTableFieldPersistenceInfos);

            var items = dataTable.AsEnumerable()
                .Select(r => new { Key = (int) r[0], Other = r[1] })
                .ToArray();

            var toDelete = items
                .GroupBy(i => i.Other)
                .Where(g => g.Count() > 1)
                .SelectMany(g => g.Where(i => i.Key == sourceID))
                .ToArray();

            var otherSideIDsToDelete = toDelete.Select(i => i.Other).ToArray();

            if (toDelete.Length > 0)
            {
                var otherSideField = (EntityField2) linkTableFields[1];
                var filter = sourceFilter & otherSideField == otherSideIDsToDelete;

                DeleteEntitiesDirectly(linkTableEntity.GetType(), filter);
            }

            return items.Any(i => !otherSideIDsToDelete.Contains(i.Other))
                ? ReplaceForeignKeyIDsOnRelationshipDirectly(relation, sourceID, targetID)
                : 0;
        }
simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 26-Aug-2021 19:01:18   

Found it.

var queryParameters = new QueryParameters(linkTableFields, linkTableFieldPersistenceInfos, selectFilter, 0, null, null, null, true);
var selectQuery = QueryCreationManagerAce.CreateSelectDQInternal(queryParameters);