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 (ie Employee and EmployeeDetails - 1:1)
Anyone to point me in the right direction?
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.