DataMore1 dm1 = null;
DataMore2 dm2 = null;
var list = session.QueryOver<Data>()
.JoinAlias(data => data.DataMore1, () => dm1, NHibernate.SqlCommand.JoinType.LeftOuterJoin, Expression.Eq("Segment", 0))
.JoinAlias(data => data.DataMore2, () => dm2, NHibernate.SqlCommand.JoinType.LeftOuterJoin, Expression.Eq("Segment", 0))
.Select(d =>
new Data ()
{
PlantID = d.PlantID,
AreaID = d.AreaID,
CellID = d.CellID,
DeviceID = d.DeviceID,
StartDateTime = d.StartDateTime,
DataPoint01 = d.DataPoint01,
DataMore1 = new List<DataMore1>(new List<DataMore1>
{
new DataMore1 { Segment = dm1.Segment, DataPoint101 = dm1.DataPoint101 }
}),
DataMore2 = new List<DataMore2>(new List<DataMore2>
{
new DataMore2 { Segment = dm2.Segment, DataPoint201 = dm2.DataPoint201 }
})
})
.List<Data>();
产生此异常。
variable 'd' of type 'FNHSamples.Data' referenced from scope '', but it is not defined
答案 0 :(得分:-2)
在定义d
后,您错过了一个开放的大括号。
我也添加了一个回报。
尝试以下方法:
DataMore1 dm1 = null;
DataMore2 dm2 = null;
var list = session.QueryOver<Data>()
.JoinAlias(data => data.DataMore1, () => dm1, NHibernate.SqlCommand.JoinType.LeftOuterJoin, Expression.Eq("Segment", 0))
.JoinAlias(data => data.DataMore2, () => dm2, NHibernate.SqlCommand.JoinType.LeftOuterJoin, Expression.Eq("Segment", 0))
.ToList()
.Select(d =>
{
return new Data ()
{
PlantID = d.PlantID,
AreaID = d.AreaID,
CellID = d.CellID,
DeviceID = d.DeviceID,
StartDateTime = d.StartDateTime,
DataPoint01 = d.DataPoint01,
DataMore1 = new List<DataMore1>(new List<DataMore1>{new DataMore1 { Segment = dm1.Segment, DataPoint101 = dm1.DataPoint101 }}),
DataMore2 = new List<DataMore2>(new List<DataMore2>{new DataMore2 { Segment = dm2.Segment, DataPoint201 = dm2.DataPoint201 }})
};
})
.List<Data>();