Nhibernate / fluenthibernate throws a StackOverflowException

In my project, I use NHibernate / FluentNHibernate, and I work with two entities, contracts and services.

This is my type of contract:

[Serializable]
public partial class TTLCContract
{
    public virtual long? Id { get; set; }
    // other properties here
    public virtual Iesi.Collections.Generic.ISet<TTLCService> Services { get; set; }

    // implementation of Equals
    // and GetHashCode here
}

and this is my type of service:

[Serializable]
public partial class TTLCService
{
    public virtual long? Id { get; set; }
    // other properties here
    public virtual Activity.Models.TTLCContract Contract { get; set; }

    // implementation of Equals
    // and GetHashCode here
}

Well, as you can see, I want my contract object to have many services, and each Service should have a link to the parent Contract.

I am using FluentNhibernate. So my mapping file looks like this:

public TTLCContractMapping()
{
    Table("tab_tlc_contracts");
    Id(x => x.Id, "tlc_contract_id");
    HasMany(x => x.Services)
            .Inverse()
            .Cascade.All()
            .KeyColumn("tlc_contract_id")
            .AsSet();
}

and

public TTLCServiceMapping()
{
     Table("tab_tlc_services");

     Id(x => x.Id, "tlc_service_id");
     References(x => x.Contract)
         .Not.Nullable()
         .Column("tlc_contract_id");
}

and here is my problem: if I get a list of all contracts in db, it works. if I get a list of all services in this contract, I get a StackOverflowException ....

Do you see something wrong with what I wrote? I made a mistake?

Please let me know if you need more information.

, , ... , , , , .

, , ... !

, , .

+3
2

, (TTLCContract TTLCService) GetHashCode().

, ...

TTLCContract GetHashCode() GetHashCode - . "", , Service.GetHashCode(). : GetHashCode() . - .

, Contract.GetHashCode() Service.GetHashCode() Service.GetHashCode() Contract.GetHashCode(). StackOverflowException.

, , : , .

, .

+1

, . , , , , ...

nhibernate, , .

0

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


All Articles