我对 NHibernate 有问题,有时它不会更新 ID 属性
用户地图类
public class SfGuardUserMap : ClassMap<User> {
public SfGuardUserMap() {
Table("sf_guard_user");
LazyLoad();
Id(x => x.Id).GeneratedBy.Identity().Column("id");
Map(x => x.FirstName).Column("first_name");
Map(x => x.LastName).Column("last_name");
Map(x => x.EmailAddress).Column("email_address").Not.Nullable();
Map(x => x.Sex).Column("sex").Not.Nullable();
Map(x => x.Lang).Column("lang");
Map(x => x.City).Column("city");
可执行代码
var user = new User
{
FirstName = usr.FirstName,
EmailAddress = usr.Email,
LastName = usr.LastName,
Sex = usr.Sex,
Birthdate = usr.Birthday,
IsActive = User.IS_ACTIVE_ACTIVE
};
var t = (int)session.Save(user);
session.Flush();
我遇到了问题,user.Id 始终为 0。但是当我重新启动 iis 时,我的问题就消失了。
我对其他班级也有同样的问题。这是我打电话时向数据库插入的任何属性Save
吗?