nHibernate, No row with the given identifier exists

前端 未结 3 886
清歌不尽
清歌不尽 2020-12-23 17:07

I have a mapping along the lines of this.



        
相关标签:
3条回答
  • 2020-12-23 17:47

    Try that...

    public void Override(ModelMapper modelMapper) {
        modelMapper.Class<T>(c => { 
            c.ManyToOne(m => m.FKObj, r => {
                r.Column("FKColumn");
                r.NotFound(NotFoundMode.Ignore); // THIS IS IMPORTANT!!!
            });
        });
    }
    
    0 讨论(0)
  • 2020-12-23 18:02

    Ok, I found the answer. Add the

    not-found="ignore"
    

    attribute to the property KeyField:

    <many-to-one name="KeyField" not-found="ignore" class="Model.Entities.Key, Model" column="field_id" />
    
    0 讨论(0)
  • 2020-12-23 18:02

    In my case the problem was because a foreign key constraint was not enforced by MyISAM engine and therefore one of the rows ended up pointing to a non-existant value and the proxy threw an exception. I would recommend checking your dataset is consistent in this case.

    0 讨论(0)
提交回复
热议问题