Guys,
I'm actually writing similar code to the HnD forum however this is very limited, just to attach files to documents e.g. orders / invoices.
I want to achieve something similar to HnD when creating a bindable field which indicates how many attachments are associated with a document. The HnD source has code such as this
// Add a scalar query expression to the list of fields in the typedlist. The scalar query expression
// performs a SELECT COUNT(AttachmentID) FROM Attachments WHERE MessageID = Message.MessageID
// query.
fields.DefineField(new EntityField("AmountOfAttachments",
new ScalarQueryExpression(AttachmentFields.AttachmentID.SetAggregateFunction(AggregateFunction.Count),
(AttachmentFields.MessageID == MessageFields.MessageID))), index);
However rather than having a foreign key to the message table directly in the attachment table I have a link table which joins the conversation message and the attachment record directly ( this allows other tables e.g. one which links purchase orders to attachments ). We have two core tables here
Attachment - AttachmentId and the blob
ConversationAttachment - AttachmentId and ConversationId
How should I change this code to incorporate this additional join, or should I not use the
ScalarQueryExpression and instead create a relation collection.
Thoughts?