如何为 List创建映射在 FluentNhibernate 中?
我正在尝试使用 Fluent NHibernate 为以下模型创建映射文件。但是,我不确定如何在映射文件中对 List<
进行映射。
public class MyClass
{
public virtual Guid Id { get; set; }
public virtual string Name { get; set; }
public virtual List<string> MagicStrings { get; set; }
}
public class EnvironmentMapping : ClassMap<Models.Environment>
{
public EnvironmentMapping()
{
Id(x => x.Id);
Map(x => x.Name);
//HasMany(x => string) What should this be ?
}
}
I am trying to create a mapping file for the following Model using Fluent NHibernate. But, I am not sure of how to do the mapping for the List<<string>string>
in the mapping file.
public class MyClass
{
public virtual Guid Id { get; set; }
public virtual string Name { get; set; }
public virtual List<string> MagicStrings { get; set; }
}
public class EnvironmentMapping : ClassMap<Models.Environment>
{
public EnvironmentMapping()
{
Id(x => x.Id);
Map(x => x.Name);
//HasMany(x => string) What should this be ?
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这并不完全是您要问的,但我只是想指出 FNH Automapping 将映射您的类,绝对不需要程序员的进一步帮助 - 即您不需要额外的映射类。
您只需将该成员声明为 IList,而不是 List。 (实际上,我认为您也必须使用 IList 进行常规 FNH 映射)。
进一步的一点 - 自动映射值类型(例如字符串和整数)存在一个错误,该错误最近已修复,因此如果您决定采用自动映射路线(我强烈推荐,顺便说一句,请确保您使用的是最新的 FNH 版本) !)。
This is not quite what you are asking, but I just want to point out that FNH Automapping will map your class with absolutely no further help from the programmer - i.e. you don't need additional Mapping classes.
You just have to declare the member as an IList, instead of a List. (Actually, I thought you had to use IList for regular FNH mapping too).
One further point - there was a bug with automapping value types such as strings and ints, which was fixed very recently, so make sure you're using the latest FNH builds if you decide to go the Automapping route (which I highly recommend, BTW!).
我找到了解决问题的方法,在我的情况下,我必须为 MyStrings 创建一个单独的表,并与 MyClass 建立外键关系。
I found a solution for my problem, in my situation I have to create a separate table for MyStrings and have a foreign key relation with MyClass.