Derived Models CreatePkPredicate only includes one primary key when the entity has more

Posts   
 
    
TomDog
User
Posts: 618
Joined: 25-Oct-2005
# Posted on: 25-Jan-2018 04:19:31   

I created a Derived Model of northwind OrderDetail and in OrderDetailPersistence the CreatePkPredicate methods only used OrderId and not ProductId as well e.g

        /// <summary>Creates a primary key predicate to be used in a Where() clause in a Linq query which is executed on the database to fetch the original entity instance
        /// the specified <see cref="dto"/> object was projected from.</summary>
        /// <param name="dto">The dto object for which the primary key predicate has to be created for.</param>
        /// <returns>ready to use expression</returns>
        public static System.Linq.Expressions.Expression<Func<Northwind.DAL.EntityClasses.OrderDetailEntity, bool>> CreatePkPredicate(Dm.DtoClasses.OrderDetail dto)
        {
            return p__0 => p__0.OrderId == dto.OrderId;
        }

        /// <summary>Creates a primary key predicate to be used in a Where() clause in a Linq query which is executed on the database to fetch the original entity instances
        /// the specified set of <see cref="dtos"/> objects was projected from.</summary>
        /// <param name="dtos">The dto objects for which the primary key predicate has to be created for.</param>
        /// <returns>ready to use expression</returns>
        public static System.Linq.Expressions.Expression<Func<Northwind.DAL.EntityClasses.OrderDetailEntity, bool>> CreatePkPredicate(IEnumerable<Dm.DtoClasses.OrderDetail> dtos)
        {
            var ids = dtos.Select(p__1=>p__1.OrderId).ToList();
            return p__0 => ids.Contains(p__0.OrderId);
        }

        /// <summary>Creates a primary key predicate to be used in a Where() clause in a Linq query on an IEnumerable in-memory set of entity instances
        /// to retrieve the original entity instance the specified <see cref="dto"/> object was projected from.</summary>
        /// <param name="dto">The dto object for which the primary key predicate has to be created for.</param>
        /// <returns>ready to use func</returns>
        public static Func<Northwind.DAL.EntityClasses.OrderDetailEntity, bool> CreateInMemoryPkPredicate(Dm.DtoClasses.OrderDetail dto)
        {
            return p__0 => p__0.OrderId == dto.OrderId;
        }

Happens with all compound PK's I've seen.

Version 5.3.3 and 5.2

Jeremy Thomas
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 25-Jan-2018 11:56:38   

True. This is a limitation as a derived element has just 1 ID field. It picks the first one and ignores the rest. (as documents in a DocDB for instance don't have compound PKs either).

That said, for this particular method, it could perhaps be fixed if the template would check whether all fields in the PK of the entity type are in the derived element and if so, add them to the comparison.

(edit) the change will not be made to v5.3 but to v5.4 at the soonest, as it's a breaking change.

Frans Bouma | Lead developer LLBLGen Pro