Have Books class.
public class Books
{
public virtual int Id { get; set; }
public virtual string Title { get; set; }
public virtual string Category { get; set; }
public virtual string ISBN { get; set; }
public virtual string Description { get; set; }
public virtual string Image { get; set; }
public virtual int CategoryId { get; set; }
public Categories Categories { get; set; }
public virtual IList<Comments> Comments { get; set; }
public Books()
{
Comments = new List<Comments>();
}
}
Also Comments Class.
public class Comments
{
public virtual int Id { get; set; }
public virtual string CommentText { get; set; }
public virtual DateTime Date { get; set; }
public virtual int IdBook { get; set; }
public Books Books { get; set; }
}
My map code for Books class :
public class BooksMap : ClassMap <Books>
{
public BooksMap()
{
Id(x => x.Id);
Map(x => x.Title);
Map(x => x.ISBN);
Map(x => x.Description);
Map(x => x.Category);
Map(x => x.Image);
Map(x => x.CategoryId);
//reference to categories
References(x => x.Categories).Column("Id").Not.Nullable();
//inverse reference (hasmany comments, rating)
HasMany(x => x.Comments).Cascade.All().Inverse();
}
}
Also Comments map >
public class CommentsMap:ClassMap<Comments>
{
public CommentsMap()
{
Id(x => x.Id);
Map(x => x.CommentText);
Map(x => x.Date);
Map(x => x.IdBook);
References(x => x.Books).Column("Id").Not.Nullable();
}
}
My question is : am I doing it right? - and how to make queries with this mapings for example criteria language?