1

I've got a object (Filter) that's defined something like this

public class Filter
{
    public int FilterId { get; set; }

        public string Name { get; set; }

        public IList<User> Users { get; set; }
}

If possible, I'd like to store the object in multiple tables (sometimes spanning multiple rows)

Given an initialization of the Filter like this:

Filter myFilter = new Filter();
myFilter.FilterId = 1;
myFilter.Name = "Name of my filter";
myFilter.Users.Add(new User("Joe", 10));
myFilter.Users.Add(new User("Jim", 20));

..I'd like it to be persisted in tables "Filter" and "Filter_User"

Filter would end up with:

1 Name of my Filter

Filter_User would contain

1 10 (ref. to Joe's ID) 1 20 (ref. to Jim's ID)

I've been looking at the documentation and all I can find is using the element in my mapping file. But as far as I can tell it will only let me do that with a component-relationship (i.e. Employee and EmployeeDetails - 1:1)

Anyone to point me in the right direction?

1 Answer 1

3

I think you're just looking for a many-to-many association ? You're not constrained using a component relationship.

You could take a look at the many-to-many mapping type ?

<set name="Users" table="Filter_User">
  <key column="filterid" />
  <many-to-many column="userid" class="User" />
</set>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.