如何使用Fluent-NHibernate和MySQL指定自动递增(int)标识列 [英] How to specify an auto-incrementing (int) identity column using Fluent-NHibernate and MySQL

查看:388
本文介绍了如何使用Fluent-NHibernate和MySQL指定自动递增(int)标识列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题基本上说这一切...我试图指定一个自动增量(int)标识列使用Fluent-NHibernate和MySQL。我尝试了以下变化...

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

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


...并尝试设置每个默认值。



注意:我正在使用int数据类型,并收到错误,如...


输入字符串格式不正确。


或...


字段'ID'没有默认值'


解决方案

在MySQL中,您可以创建一个列,并提及其属性为AUTO_INCREMENT和DEFAULT VALUE 1(或任何你想要的),为什么你不使用它?



- 干杯


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'

解决方案

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

这篇关于如何使用Fluent-NHibernate和MySQL指定自动递增(int)标识列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆