简体   繁体   English

使用Asp和C#在MySql中进行Nhibernate数据库连接

[英]Nhibernate database connection in MySql using Asp& C#

I'm trying to save the values in database. 我正在尝试将值保存在数据库中。 But here I can able to save only once after executing. 但是在这里,执行后我只能保存一次。 During second time it shows inner exception as "{"Duplicate entry '' for key 1"}" 在第二次显示为“ {”键1“}的重复条目”的内部异常

Looks like you're assigning the same key to a new object. 看起来您正在将相同的键分配给新对象。 I mean maybe you're trying to Save a new object in the database with the same key/Id. 我的意思是也许您正在尝试使用相同的键/ ID将新对象保存在数据库中。 If you're updating the object with Id/Key = 1 you should use an update command instead. 如果要使用Id / Key = 1更新对象,则应改用update命令。

As Jonny Cundall said we need more information about your NHibernate mapping to see what you're doing... 正如Jonny Cundall所说,我们需要有关您的NHibernate映射的更多信息,以了解您的工作...

Do this for you identity: 为您的身份执行此操作:

<!-- Identity mapping -->
<id name="Emp_Id">
<column name="Emp_Id" />
<generator class="native" />
</id>

Advice: do not use string as your data type for an identity column. 建议:请勿将字符串用作标识列的数据类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM