NHibernate 映射动态属性
您好,我的网站有以下数据库结构:
章节
- ID(PK、身份)
- 名称
文档
- ID(PK、身份)
- 章节 ID(FK 到章节)
文章
- ID(PK、FK 到文档)
- 标题
- 内容
链接
- ID(PK、FK 到文档)
- 标题
- SomeOtherField
MetaComponent
- Id(PK、FK 到文档)
- MetaKeywords
- MetaDescription
SectionComponents
- SectionId(FK 到部分)
- ComponentName
该网站包含多个部分(文章和上述结构中的链接)。文章和链接表使用仅适用于该特定部分的额外字段扩展了文档。每个部分都可以选择添加其他组件。元组件表是包括搜索引擎元信息的一个特定组件的示例。
我想知道是否可以映射我的应用程序,以便我可以查询所有文章并加入它以获取该特定文章的元信息。我知道我可以针对我的 Article 类添加 Meta 属性,但我希望能够轻松打开和关闭哪些组件适用于特定部分。我想我必须做一些更花哨的事情来检索这些信息,如果有人可以提供帮助,我将不胜感激。
我希望我已经把事情解释得足够清楚了。
谢谢
Hi my site has the following database structure:
Sections
- Id (PK, Identity)
- Name
Documents
- Id (PK, Identity)
- SectionId (FK to Sections)
Articles
- Id (PK, FK to Documents)
- Title
- Content
Links
- Id (PK, FK to Doucments)
- Title
- SomeOtherField
MetaComponent
- Id (PK, FK to Documents)
- MetaKeywords
- MetaDescription
SectionComponents
- SectionId (FK to Sections)
- ComponentName
The site contains multiple sections (Articles and Links in the above structure). The Articles and Links tables extend the Document with the extra fields that only apply for that particular section. Each section can optionally have additional Components added to them. The MetaComponent table is an example of one particular Component which includes the search engine meta information.
I was wondering if it's possible to map my application so i can query all Articles and join it to get the meta Information for that particular article. I know i could add a Meta property against my Article class but i want to be able to easily switch on and off which components apply to particular sections. I guess i would have to do something a little fancier to retrieve this information and would appreciate it if someone could help.
I hope i've explained things clear enough.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,nHib(或任何 ORM)的最大优势之一是,它使您能够将应用程序域视为实体,而不是表。
因此,就您的情况而言,我认为将您的文档实体视为基类,其中链接和文章是子类,这会更正确,也更容易理解。
当我们这样看时,问题的解决方案是显而易见的 - 子类映射:
* 用于映射继承的 Fluent nHib 文档,
* 更详细的信息可以在 nHib 文档。
firstly- one of the biggest advantages of nHib (or any ORM, for that matter) is that it enables you to view your app domain as entities rather than tables.
So in your case, I think it would be more correct, and more understandable, to look at your Document entity as being a base-class, of which Link and Article are sub-classes.
And when we look at it like that, the solution to your problem is obvious- mapping of subclasses:
* fluent nHib docs for mapping inheritance,
* more detailed info can be found in the nHib docs.