FluentNHibernate: multiple one-to-many relationships between the same objects

I am working on a bug tracking application. There are tickets, and each ticket has an open user and a designated user. So basically, I have two entities that have two β€œone or two” relationships with each other. They are schematically:

User:

public class User
{
    public virtual int Id { get; protected set; }
    ...

    public virtual IList<Ticket> OpenedTickets { get; set; }
    public virtual IList<Ticket> AssignedTickets { get; set; }
}

tickets:

public class Ticket
{
    public virtual int Id { get; protected set; }
    ...

    [Required]
    public virtual User OpenerUser { get; set; }
    public virtual User AssignedUser { get; set; }
}

I am using the FluentNHibernate auto-matching feature.

The problem is that regardless of whether the connection is established, on the user side, both collections always contain the same data. I guess Fluent cannot determine which end of the relationship refers to where.

I googled around but didn't find anything useful.

EDIT 2:

, IHasManyConvention. , IHasManyConvention , IReferenceConvention. .

, ForeignKey.EndsWith("Id") .

, , , .

+3
1

. , ():

class HasManyConvention : IHasManyConvention
{
    public void Apply(IOneToManyCollectionInstance instance)
    {
        instance.Key.Column(instance.Member.Name);
    }
}

// register convention using:
autoMapping.Conventions.Add(new HasManyConvention());
+2

Source: https://habr.com/ru/post/1744249/


All Articles