I have code that can retrieve all entities that contain a specific relationship, for example:
var bucket = new RelationPredicateBucket();
bucket.Relations.Add(MessageEntity.Relations.MessageTemplateReferenceEntityUsingMessageId);
var messageEntities = new EntityCollection<MessageEntity>();
using (var myAdapter = PersistenceLayer.GetDataAccessAdapter())
{
myAdapter.FetchEntityCollection(messageEntities, bucket);
}
It works great. Now I want to get all entities in the message table that DO NOT have the corresponding row in the xref MessageTemplate table. That is where MessageEntity.Relations.MessageTemplateReferenceEntityUsingMessageId is null / false / nonexistent.
Here is a phenomenal hack that one of my teammates did to make this work a few years ago (the above code entity collection is in templatedMessages below):
bucket.PredicateExpression.Add(MessageFields.Id
!= templatedMessages.Select(m =>
m.Id).ToArray());
This really worked until recently, when the number of templatedMessages in the table grew beyond 2100, and the method began to throw these exceptions:
(TDS) (RPC). RPC. 2100.
, SQL , , . LLBLGen? SQL - :
SELECT m.* FROM Message m
WHERE NOT EXISTS (SELECT 1 FROM MessageTemplate mt WHERE mt.MessageID = m.ID)
LLBLGen?