流畅的 NHibernate 映射
我已将值插入“品牌”和“型号”表中。但两个表中的 Id 均以偶数和奇数显示。
Id 列假设为 .GenerateBy.Identity();父表和子表的 Id 列中均为 (1,2,3,4......)。
MAKE
ID | Name
-----------
1 | BMW
3 | Mercedes
MODELS
ID | Name | MakeID
------------------
2 | Ex | 1
4 | Lx | 3
如何解决此问题以避免将偶数或奇数插入父表和子表中。
public MakeMap()
{
Id(x => x.Id).GeneratedBy.Identity();
Map(x => x.Name);
HasMany<Models>(x => x.Models).Cascade.All().KeyColumn("MakeId");
Table("Make");
}
public ModelsMap()
{
Id(x => x.Id).GeneratedBy.Identity();
Map(x => x.Name);
References<Make>(x => x.Make).Column("MakeId");
Table("Models");
}
任何帮助将不胜感激。
谢谢,
I've inserted value into Make and Models table. But the Ids in both tables are showing in Even and Odd number.
The Id column suppose to .GeneratedBy.Identity(); as (1,2,3,4.......) in both the parent and child tables Id column.
MAKE
ID | Name
-----------
1 | BMW
3 | Mercedes
MODELS
ID | Name | MakeID
------------------
2 | Ex | 1
4 | Lx | 3
How to fix this problem to avoid inserting Even or Odd numbers into parent and child tables.
public MakeMap()
{
Id(x => x.Id).GeneratedBy.Identity();
Map(x => x.Name);
HasMany<Models>(x => x.Models).Cascade.All().KeyColumn("MakeId");
Table("Make");
}
public ModelsMap()
{
Id(x => x.Id).GeneratedBy.Identity();
Map(x => x.Name);
References<Make>(x => x.Make).Column("MakeId");
Table("Models");
}
Any help will greatly appreciated.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定这是由您的映射引起的吗?我不知道您使用的是什么数据库,但是您的身份规范(以 SQL Server 为例)是否可能设置为递增 2?
Are you sure that this is being caused by your mapping? I don't know what database you are using, but is it possible that your Identity Specification (using SQL Server as an example) is set up to increment by 2?