Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5849129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:57:23+00:00 2026-05-22T12:57:23+00:00

I’ve asked a similar question, but I’ve given up on the idea I had

  • 0

I’ve asked a similar question, but I’ve given up on the idea I had there to solve this problem so I would like some help solving this in a neat way instead.

I’ve got tables

Image - (Id, Name, RelativeFilePath)
ImageFilter - (Id, Type)
ImageContext - (Id, Name, ...)
ImageContextImage - (Id, ImageContextId, ImageId, ImageFilterId)

Example of data:

ImageContextImage      Id        ImageContextId         ImageId        ImageFilterId
                       1         1                      1              1
                       2         1                      1              2
                       3         2                      1              1
                       4         3                      2              1

As you can see, an image in a context can have several filters applied.

All of my entities are very simple, except this mapping of the above. Currently I’ve got

ImageContext
    public virtual int Id
    public virtual string Name
    public virtual IList<ImageContextImage> Images

ImageContextImage
    public virtual int Id
    public virtual ImageContext Context
    public virtual Image Image
    public virtual ImageFilter ImageFilter

The above is very easy to map, but for each image I then get multiple ImageContextImage objects. I would rather have ImageContextImage contain a list of ImageFilter, so that I can simply iterate through that collection. I’ve tried alot of permutations of AsTernaryAssociation() and it complains that I need a Dictionary, but I want multiple values per key! Any ideas?

Any ideas? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:57:24+00:00Added an answer on May 22, 2026 at 12:57 pm

    Ternary association can be replaced with binary associations but a new entity will appear after the replacement (Removing Ternary relationship types). It is ImageContextImage entity in your case and the hard part is to find best name for such entity. Your example is very close to this replacement.

    ImageContextImage entity:

    public virtual int Id { get; set; }
    public virtual Image Image { get; set; }
    public virtual ImageContext Context { get; set; }
    public virtual IList<ImageFilter> Filters { get; set; }
    

    and it’s mapping:

    Id(x => x.Id);
    References(x => x.Image);
    References(x => x.Context);
    HasManyToMany(x => x.Filters); // filters are referenced via many-to-many relation
    

    ImageContext entity:

    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
    public virtual IList<ImageContextImage> ImageContextImageList { get; set; }
    

    and it’s mapping:

    Id(x => x.Id);
    Map(x => x.Name);
    HasMany(x => x.ImageContextImageList)
        .Inverse(); // to aggregate all ImageContextImage that are fererencing this instnstance of ImageContext
        .KeyColumn("Context_id");
    

    Corresponding database schema is slightly different:

    ImageContextImage(Id, Image_id, Context_id)
    

    and new association table must be created for the many-to-many relation:

    ImageFilterToImageContextImage(ImageContextImage_id, ImageFilter_id)
    

    Note that this is only a sketch of one possible approach. Many details depends on your problem domain and must be tweaked before it is ready for production:) – e.g.cascades.

    I have never used AsTernaryAssociation but it seems interesting. I will investigate it later, thank you for the inspiration:).

    EDIT:
    Ternary association can be implemented by slightly different mapping (using composite-element) but there is still additional entity – ImageContextImage which is mapped as component in this case:

    public class ImageContext
    {
        public virtual int Id { get; set; }
        public virtual string Name { get; set; }
        public virtual IList<ImageContextImage> ImageContextImageList { get; set; }
    
        public ImageContext()
        {
            ImageContextImageList = new List<ImageContextImage>();
        }
    }
    
    public class ImageContextMap : ClassMap<ImageContext>
    {
        public ImageContextMap()
        {
            Id(x => x.Id);
            Map(x => x.Name);
            HasMany(x => x.ImageContextImageList).Component(c =>
            {
                c.References(x => x.Image);
                c.References(x => x.Filter);
            }).Cascade.AllDeleteOrphan();
        }
    }
    
    public class ImageContextImage
    {
        public virtual Image Image { get; set; }
        public virtual ImageFilter Filter { get; set; }
    }
    

    ImageContext class can be extended by these methods to make things simpler:

    public virtual IEnumerable<Image> AssociatedImages
    {
        get
        {
            return ImageContextImageList.Select(x => x.Image).Distinct().ToList();
        }
    }
    
    public virtual IEnumerable<ImageFilter> GetFilters(Image image)
    {
        return ImageContextImageList.Where(x => x.Image == image).Select(x => x.Filter).ToList();
    }
    

    No success with AsTernaryAssociation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.