views:

9

answers:

0

I have the following entities

public class Client
{
    public virtual int Id{get;set;}
    public virtual IList<Telephone> Telephones { get; private set; }
}

public class User
{
    public virtual int Id{get;set;}
    public virtual IList<Telephone> Telephones { get; private set; }
}

public class Telephone
{
    public virtual int Id{get;set;}
    public virtual string Number { get; set; }
    public virtual string Extension { get; set; }
    public virtual TelephoneType TelephoneType { get; set; }
}

Client as mapping like this

HasManyToMany<Telephone>(x => x.Telephones)
.Table("tblClientTel")
.ParentKeyColumn("ClientId")
.ChildKeyColumn("TelId")
.LazyLoad()
.Cascade.SaveUpdate();

User as mapping like this

HasManyToMany<Telephone>(x => x.Telephones)
.Table("tblUserTel")
.ParentKeyColumn("UserId")
.ChildKeyColumn("TelId")
.LazyLoad()
.Cascade.SaveUpdate();

And Telephone like this

   public TelephoneMap()
    {
        Table("tblTel");
        Id(x => x.Id, "Id");
        LazyLoad();
        References<TelephoneType>(x => x.TelephoneType, "TypeId")
            .Not.Nullable()
            .Cascade.None()
            .Not.LazyLoad();
        Map(x => x.Number, "Number")
            .Not.Nullable()
            .Length(15);
        Map(x => x.Extension, "Extension")
            .Nullable()
            .Length(10);
    }

How can i query for all the telephone entities of a list of client ? I've tried this

ICriteria criteria = base.CreateCriteria<Client>(null);
return base.CreateCriteria
.SetProjection(Projections.ProjectionList()
.Add(Projections.Property("Telephones"))
)
.Add(Expression.In("Id", clientIds))
.SetFetchMode("Telephones", FetchMode.Eager)
.List<Telephone>();

But it returns the client Id