首页新闻找找看学习计划

fluentNhibernate问题。高手进,大神进

0
悬赏园豆:5 [待解决问题]

此 SqlParameterCollection 的 Count=4 的索引 4 无效。哪位大神看看

 添加操作:

DateTime createTime = DateTime.Now;
User user = new User()
{
CreateTime = createTime,
Password = "ilovecandy",
UserName = "james",
};

UserDetail detail = new UserDetail
{
FirstName = "James", LastName = "Ying" ,
LastUpdated = createTime,
};
detail.User = user;
user.UserDetail = detail;
Save(user);

插入操作的时候报上面的错!!

实体:

public class User : Entity
{
[Length(Message = "用户编号")]
public virtual int UserID { get; set; }

[Length(Message = "用户名称")]
[NotNull]
public virtual string UserName { get; set; }

[Length(Message = "性别:1=男,2=女")]
[NotNull]
public virtual EnumUserSex Sex { get; set; }

[Length(Message = "创建用户")]
[NotNull]
public virtual string Password { get; set; }

[Length(Message = "创建时间")]
[NotNull]
public virtual DateTime CreateTime { get; set; }

public virtual UserDetail UserDetail { get; set; }
}

/// <summary>
/// 性别:1=男,2=女
/// </summary>
public enum EnumUserSex
{
/// <summary>
/// 男
/// </summary>
boy = 1,

/// <summary>
/// 女
/// </summary>
grid = 2,
}

 

public class UserDetail : Entity
{
[NotNull]
public virtual int UD_UserID { get; set; }

[NotNull]
public virtual DateTime LastUpdated { get; set; }

[NotNull]
public virtual string FirstName { get; set; }

[NotNull]
public virtual string LastName { get; set; }

public virtual User User { get; set; }
}

 

mapping:

public class UserMap : IAutoMappingOverride<User>
{
public void Override(FluentNHibernate.Automapping.AutoMapping<User> mapping)
{
mapping.Table("NA_User");

mapping.Id(m => m.UserID).GeneratedBy.Identity();//通过自增来的

mapping.Map(m => m.Sex).CustomType<EnumUserSex>().CustomSqlType("tinyint");

mapping.HasOne<UserDetail>(m => m.UserDetail).Cascade.All();
}
}

 

public class UserDetailMap : IAutoMappingOverride<UserDetail>
{
public void Override(FluentNHibernate.Automapping.AutoMapping<UserDetail> mapping)
{
//cascade="all",代表的是无论什么操作,都会同时操作关联对象
mapping.Table("NA_UserDetail");
mapping.Id(u => u.UD_UserID).Column("UD_UserID").GeneratedBy.Foreign("User");
mapping.HasOne<User>(d => d.User).Constrained();
mapping.Map(u => u.LastUpdated).Nullable();
}
}

彬彬@科比的主页 彬彬@科比 | 初学一级 | 园豆:43
提问于:2014-05-04 00:42
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册