我有一个包含关键字的表。我有几个其他表可以有多个关键字(从关键字表中提取)。这是我所拥有的,它有效,但感觉好像有更好的方法来映射它。我只是不确定它会是什么(如果有的话)
public class Keyword
{
public virtual int Id {get; protected set;}
public virtual string Name {get; set;}
}
public class KeywordMap : ClassMap<Keyword>
{
public KeywordMap()
{
Id(x => x.Id).Not.Nullable().GeneratedBy.Identity();
Map(x => x.Name).Not.Nullable.Length(100);
}
}
public class Article
{
public virtual int Id {get; protected set;}
//... other properties omitted
public virtual IList<Keyword> Keywords {get; set;}
}
public class ArticleMap : ClassMap<Article>
{
public ArticleMap()
{
Id(x => x.Id).Not.Nullable().GeneratedBy.Identity();
HasMany(x => x.Keywords).Inverse().Cascade.Delete();
}
}
public class Picture
{
public virtual int Id {get; protected set;}
//... other properties omitted
public virtual IList<Keyword> Keywords {get; set;}
}
public class PictureMap : ClassMap<Picture>
{
public PictureMap()
{
Id(x => x.Id).Not.Nullable().GeneratedBy.Identity();
HasMany(x => x.Keywords).Inverse().Cascade.Delete();
}
}