0

I have two tables

Table A:
Id  | Attachment_id
1   | 123

Table B:
Id | doc_name |Attachment_id | version
1  | sab.txt  | 123          | 1
2  | sab.txt  | 123          | 2

When i upload a file with same name and content it is saved with increasing versions. As the attachment_id is repeating it's causing a blow up. Can you please let me know how to provide the FluentNhibernate mappings to fetch only the latest version of the doc (i.e 2, sab.txt,123,2)

Firo
  • 30,626
  • 4
  • 55
  • 94
user1618587
  • 47
  • 1
  • 5

1 Answers1

1

using a Formula which fetches the last entry

References(x => x.LastAttachment)
    .Formula("(Select b.Id FROM B b WHERE b.Attachment_id = Attachment_id ORDER BY version DESC LIMIT 1)");
Mike
  • 4,257
  • 3
  • 33
  • 47
Firo
  • 30,626
  • 4
  • 55
  • 94