开发者

Nhibernate Fluent domain Object with Id(x => x.id).GeneratedBy.Assigned not saveable

I am using for some legacy db the corresponding domainclasses with mappings. Now the Ids of the entities are calculated by some stored Procedure in the DB which gives back the Id for the new row.(Its legacy, I cant change this) Now I create the new entity , set the Id and Call Save. But nothing happens. no exeption. Even NH Profiler does not say a bit. its as the Save call does nothing. I expect that NH thinks that the record is already in the db because its got an Id already. But I am using Id(x => x.id).GeneratedBy.Assigned() and intetionally the Session.Save(object) method.

I am confused. I saw so many samples there it worked.

does any body have any ideas about it?

public class Appendix
{
    public virtual int id { get; set; }
    public virtual AppendixHierarchy AppendixHierachy { get; set; }
    public virtual byte[] appendix { get; set; }
}       

public clas开发者_C百科s AppendixMap : ClassMap<Appendix>
{
    public AppendixMap ()
    {
        WithTable("appendix");
        Id(x => x.id).GeneratedBy.Assigned();
        References(x => x.AppendixHierachy).ColumnName("appendixHierarchyId");
        Map(x => x.appendix);
    }
}


Stupid question, but the reason of this problem in many cases: did you commit the session? NH caches the changes (when calling Save, nothing happens yet) until it is forced to flush it or until you commit the session. When you create your own ADO connection, you need also to call Flush before committing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜