映射多对多关系的问题(通过代码映射)
我正在通过代码使用新的 NHibernate 3.2 映射(不流畅的 nhibernate),并且在映射多对多关系时遇到一些问题。
我想映射这些实体
public class Article
{
public virtual Guid Id { set; get; }
public virtual string Content { set; get; }
public virtual string Title { set; get; }
public virtual IList<Tag> Tags { set; get; }
}
public class Tag
{
public virtual Guid Id { set; get; }
public virtual string Name { set; get; }
public virtual IList<Article> Articles { set; get; }
}
public class ArticleTag
{
public virtual Article Article { set; get; }
public virtual Tag Tag { set; get; }
}
我的映射看起来
public class TagMapping : ClassMapping<Tag>
{
public TagMapping()
{
Id<Guid>(x => x.Id);
Property<string>(x => x.Name);
Bag<Article>(x => x.Articles, x => x.Inverse(true), x => x.ManyToMany(z =>
{
z.Column("Article");
z.Lazy(LazyRelation.Proxy);
}));
}
}
public class ArticleTagMapping : ClassMapping<ArticleTag>
{
public ArticleTagMapping()
{
ManyToOne<Article>(x => x.Article, x => { });
ManyToOne<Tag>(x => x.Tag, x => { });
}
}
public class ArticleMapping : ClassMapping<Article>
{
public ArticleMapping()
{
Id<Guid>(x => x.Id, x => x.Generator(Generators.Guid));
Property<string>(x => x.Content, x => x.Length(4002));
Property<string>(x => x.Title);
Bag<Tag>(x => x.Tags, x =>{ }, x => x.ManyToMany(z =>
{
z.Column("Tag");
z.Lazy(LazyRelation.Proxy);
}));
}
}
唯一的问题是,当我使用此模式在数据库中生成表时,我有两个附加表。我必须更改什么才能禁用生成这两个表(文章和标签)?
I'm using a new to NHibernate 3.2 mapping by code (not fluent nhibernate) and I have a little problem with mapping a many-to-many relation.
I want to map these entities
public class Article
{
public virtual Guid Id { set; get; }
public virtual string Content { set; get; }
public virtual string Title { set; get; }
public virtual IList<Tag> Tags { set; get; }
}
public class Tag
{
public virtual Guid Id { set; get; }
public virtual string Name { set; get; }
public virtual IList<Article> Articles { set; get; }
}
public class ArticleTag
{
public virtual Article Article { set; get; }
public virtual Tag Tag { set; get; }
}
My mapping looks that
public class TagMapping : ClassMapping<Tag>
{
public TagMapping()
{
Id<Guid>(x => x.Id);
Property<string>(x => x.Name);
Bag<Article>(x => x.Articles, x => x.Inverse(true), x => x.ManyToMany(z =>
{
z.Column("Article");
z.Lazy(LazyRelation.Proxy);
}));
}
}
public class ArticleTagMapping : ClassMapping<ArticleTag>
{
public ArticleTagMapping()
{
ManyToOne<Article>(x => x.Article, x => { });
ManyToOne<Tag>(x => x.Tag, x => { });
}
}
public class ArticleMapping : ClassMapping<Article>
{
public ArticleMapping()
{
Id<Guid>(x => x.Id, x => x.Generator(Generators.Guid));
Property<string>(x => x.Content, x => x.Length(4002));
Property<string>(x => x.Title);
Bag<Tag>(x => x.Tags, x =>{ }, x => x.ManyToMany(z =>
{
z.Column("Tag");
z.Lazy(LazyRelation.Proxy);
}));
}
}
The only problem is that, when I generate tables in database using this schema, I have two additional tables. What I must change to disable generating these two tables (Articles and Tags)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你真的需要这个吗?:
Do you really need this?: