开发者

nhibernate issue with "Cannot insert explicit value for identity column in table"

I seem to be having a random issue with nHibernate and inserting records.

Insert was working fine, then added a new table, and started receiving 开发者_如何学Cthe error:

Cannot insert explicit value for identity column in table '' when IDENTITY_INSERT is set to OFF

The existing tables insert also now fails. The random part comes in that if I delete my files, and re-checkout, the insert then works fine.

nHibernate version is 3.1

The identity columns is being set via:

[NHibernate.Mapping.Attributes.Generator(Class = "native")]
[NHibernate.Mapping.Attributes.Id(Name = "id")]
public virtual IdT id
{
    get { return _id; }
    set { _id = value; }
}

I tried setting to "identity", but still an issue. Not sure if there is a caching problem, but worried it could affect functionality at a later stage.


Was facing this error. I immediately realized that its an IDENTITY issue. But i had auto-increment set. So i checked my mapping file. I was quick to realize that:

    <id name="Id" access="property" column="`id`">
        <generator class="assigned" />
    </id>

has to be

    <id name="Id" access="property" column="`id`">
        <generator class="native" />
    </id>

NOTE: class="native"

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜