Let's say that I have entity and mapping classes below, and to keep things 
simple they are showing only one References/Has Many property, but imagine 
they have large number of one-to-many, many-to-many relationships.

In example classes, does it mean that an implementation of a repository's 
method that retrieve an Author object, for this purpose, let's call it 
GetAuthorById(int 
id) has to always retrieve all of author's books or can I dictate what I 
retrieve from database. For example, sometimes I would like to omit 
grabbing the list of Books if they are irrelevant. If I can do this, what 
way would you suggest to go about it? Perhaps, turn off lazy loading and 
create completely separate methods; or pass something like enum 
AuthorDetails param and based on it dictate .Query<Author>() within 
GetAuthorById(int 
id), or something completely else? 

Author.cs

public class Author{
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
    public virtual IEnumerable<Book> Books { get; set; }}

Book.cs

public class Book{
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
    public virtual Author Author { get; set; }}

AuthorMap.cs

public class AuthorMap : ClassMap<Author>{
    public ClientMap()
    {
        Id(x => x.Id).Column("PKId");
        Map(x => x.Name);
        HasMany(x => x.Books).KeyColumn("AuthorId");
        Table("Authors");
    }}

BookMap.cs

public class BookMap : ClassMap<Book>{
    public BookMap()
    {
        Id(x => x.Id).Column("PKId");
        Map(x => x.Name);
        References(x => x.Author).Column("AuthorId");
        Table("Books");
    }}

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fluent-nhibernate+unsubscr...@googlegroups.com.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
Visit this group at http://groups.google.com/group/fluent-nhibernate.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to