用于本地化的流畅 NHibernate 映射
我正在尝试从 NHibernate 映射构建数据库,但遇到了问题。
我有许多带有本地化字符串值的类:
public class MyClass1 {
public virtual int Id { get; set; }
public virtual ShortString Name { get; set; }
public virtual LongString Description { get; set; }
}
public class MyClass2 {
public virtual int Id { get; set; }
public virtual ShortString Name { get; set; }
public virtual LongString Description { get; set; }
}
像 My ShortString 和 LongString 类这样的语言
public class Language {
public virtual string Code { get; set }
public virtual string Name { get; set }
}
看起来都一样:
public class ShortString {
public virtual int Id { get; set; }
public virtual IDictionary<Language, string> Values { get; set; }
}
我想要实现的是两个表(ShortString 和 LongString),如下所示:
TABLE ShortString
-----------------
Id (int)
LanguageCode (nvarchar(8))
Value (nvarchar(256)) (or ntext for the LongString Table)
...以 Id AND LanguageCode 作为主键,语言表的外键。
在 MyClass1 和 MyClass2 表中,我希望将 NameId (int) 和 DescriptionId (int) 列分别映射到 ShortString 和 LongString 表。
我完全被困住了。我怎样才能实现这个目标?
I am trying to build a Database from NHibernate mappings and have run into a problem.
I have many classes with localized string values:
public class MyClass1 {
public virtual int Id { get; set; }
public virtual ShortString Name { get; set; }
public virtual LongString Description { get; set; }
}
public class MyClass2 {
public virtual int Id { get; set; }
public virtual ShortString Name { get; set; }
public virtual LongString Description { get; set; }
}
and Languages like
public class Language {
public virtual string Code { get; set }
public virtual string Name { get; set }
}
My ShortString and LongString classes both look the same:
public class ShortString {
public virtual int Id { get; set; }
public virtual IDictionary<Language, string> Values { get; set; }
}
What I want to achieve are two tables (ShortString and LongString) looking like this:
TABLE ShortString
-----------------
Id (int)
LanguageCode (nvarchar(8))
Value (nvarchar(256)) (or ntext for the LongString Table)
...with Id AND LanguageCode as primary keys and a ForeignKey to the Language Table.
And in the MyClass1 and MyClass2 tables, I want to have NameId (int) and DescriptionId (int) columns mapped to ShortString and LongString tables respectively.
I am totally stuck. How can I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许你可以完全放弃短字符串和长字符串
并使用以下映射
我现在无法测试它所以可能需要调整
Maybe you could ditch short and long string altogether
and use the folling Mapping
I cant test it right now so there might be tweaking nessesary