仅一侧映射时查询多对多 nhibernate
我有以下实体
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论