2

私は次のエンティティを持っています

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; }
}

このようなマッピングとしてのクライアント

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

このようなマッピングとしてのユーザー

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

そしてこのような電話

   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);
    }

クライアントのリストのすべての電話エンティティを照会するにはどうすればよいですか?私はこれを試しました

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>();

ただし、クライアントIDを返します

4

0 に答える 0