How to specify an auto-incrementing (int) identity column using Fluent-NHibernate and MySQL

两盒软妹~` 提交于 2019-12-10 15:32:11

问题


The title basically says it all... I'm trying to specify an auto-incrementing (int) identity column using Fluent-NHibernate and MySQL. I've tried the following variations...

Id(x => x.ID).GeneratedBy.Native();
Id(x => x.ID).GeneratedBy.Identity();
Id(x => x.ID).GeneratedBy.Increment();

...and tried setting default values on each.

Note: I'm using an int data type and have received errors such as...

"Input string was not in a correct format."

or...

"Field 'ID' does not have a default value'


回答1:


In MySQL you can create a column and mention its properties as AUTO_INCREMENT and DEFAULT VALUE 1 (or whatever you wish), why don't you use it?

--Cheers




回答2:


I'm using

public class User
    {
        public virtual int Id { get; set; }
        public virtual IList<Names> Names { get; set; }
        public virtual IList<Addresses> Addresses { get; set; }
    }

and mapping as Increment and works for me.

Id(x => x.Id).GeneratedBy.Increment();


来源:https://stackoverflow.com/questions/4002238/how-to-specify-an-auto-incrementing-int-identity-column-using-fluent-nhibernat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!