I have a model such as this (simplified)
public class Post
{
public string ID { get; set; }
public string Title { get; set; }
public string Body { get; set; }
public string AuthorName { get; set; }
public List<string> Attachments { get; set; }
}
In my database, I have a Post table, and a PostAttachment table
Post Attachment table has 2 columns:
PostID AttachmentKey
(The basics of this are that the attachment is uploaded to amazon s3, so the AttachmentKey is the s3 key)
What I want to do is map the AttachmentKey to the List of a returned / inserted Post object...
How would I go about doing this?
@ben-hughes You almost got it.
You do not need another mapping.
HasMany(x => x.Attachments)
.KeyColumn("PostID")
.Table("PostAttachment").Element("AttachmentKey");
Unless I misunderstood the question, it's just this:
<bag name="Attachments" table="Attachment">
<key column="PostId" />
<element column="AttachmentKey" />
</bag>
BTW, Attachments
should be an IList<string>
, not List<string>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With