How to specify auto-increment identifier (int) column using Fluent-NHibernate and MySQL

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

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

... and tried to set default values ​​for each.

Note. I use the int data type and get errors like ...

"The input string was not in the correct format."

or...

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

+4
source share
2 answers

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

- Greetings

-3
source

I use

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 an Increment and works for me.

 Id(x => x.Id).GeneratedBy.Increment(); 
+7
source

All Articles