Nhibernate复合关键问题
我有一个名为 person_skills 的表,如下所示:
person_id、skill_type_id、base_score、misc_score
有一个查找表,其中包含 Skill_types 的 id、名称。
现在棘手的是我有一个 person_id、skill_type_id 的复合键。由于一个人可能拥有 5 种技能,因此该表中会有很多条目。
目前我有一个像这样的类:
public class skill
{
int BaseScore {get;set;}
int MiscScore {get;set;}
}
然后我有一个类来包含所有这些,如下所示:
public class person_skills
{
int person_id {get;set;}
IDictionary<skill_type, skill> skills {get;set;}
}
现在我不确定这是否是处理这种关系的最佳方式,最终我需要能够为人们提供技能的链接,一人多才。
我正在考虑只放入一个自动递增 id 列并将其用作 PK,但这似乎并不理想。如果需要,我可以更改模型和数据库,但由于这是在页面的 ajax 部分中使用的,所以我需要能够更改技能,然后将它们更新到数据库中。
I have a table called person_skills like so:
person_id, skill_type_id, base_score, misc_score
There is a lookup table that contains id, name for skill_types.
Now the tricky thing is that I have a composite key for person_id, skill_type_id. There will be many entries within this table as a person may have 5 skills.
Currently I have got a class like so:
public class skill
{
int BaseScore {get;set;}
int MiscScore {get;set;}
}
Then I have a class to contain all this like below:
public class person_skills
{
int person_id {get;set;}
IDictionary<skill_type, skill> skills {get;set;}
}
Now im not sure if this is the best way to handle this relationship, ultimately I need to be able to give people a link to skills, there is one person to many skills.
I was thinking about just putting in an auto incrememnt id column and use that as the PK, but it doesn't seem ideal. I can change the models and the DB if required, but as this is used within an ajax part of a page I need to be able to change the skills and then update them into the database.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有找到实际的问题,但无论如何我都会回答。 :)
您不需要 person_skills 表的代理键。您的复合键由 person_id 和 Skill_type_id 组成,应该足够了。我相信以下类和映射反映了您在这里想要完成的任务。
类:
映射:(FluentNhibernate)
映射(hbm,由 FluentNHibernate 生成 - 我删除了不需要的输出):
I did not find an actual question but I'll answer anyway. :)
You do not need a surrogate key for the person_skills table. Your composite key, consisting of person_id and skill_type_id, should be sufficient. I believe the following classes and mappings reflect what you are trying to accomplish here.
Classes:
Mappings: (FluentNhibernate)
Mappings (hbm, generated by FluentNHibernate - I removed output that is not required):