我试图用XPO编写下一个MSSQL查询时已经打破了我的想法:
SELECT Gate.Name, grp.maxDate as 'Latest pass', a.Type, a.ReceivedTime as 'Imported at'
FROM Access AS a INNER JOIN
(SELECT GateId, MAX(OpenTime) AS maxDate
FROM Access
GROUP BY GateId) AS grp ON a.GateId = grp.GateId AND a.OpenTime = grp.maxDate INNER JOIN
Gate ON a.GateId = Gate.ID
order by Gate.ID
My Access表有大约2个记录,但它只有40个不同的GateId。我想为每个门选择一条线,如下所示:
GateName OpenTime类型导入为
.................................................. ..................................
Supergate 20/09/2013 1 21/09/2013
Ultragate 19/09/2013 0 22/09/2013
我的Access类看起来像这样:
public partial class Access : XPLiteObject
{
Gate fGateId;
[Association(@"AccessReferencesGate")]
public Gate GateId
{
get { return fGateId; }
set { SetPropertyValue<Gate>("GateId", ref fGateId, value); }
}
DateTime fOpenTime;
public DateTime OpenTime
{
get { return fOpenTime; }
set { SetPropertyValue<DateTime>("OpenTime", ref fOpenTime, value); }
}
byte fType;
public byte Type
{
get { return fType; }
set { SetPropertyValue<byte>("Type", ref fType, value); }
}
DateTime fReceivedTime;
public DateTime ReceivedTime
{
get { return fReceivedTime; }
set { SetPropertyValue<DateTime>("ReceivedTime", ref fReceivedTime, value); }
}
int fID;
[Key(true)]
public int ID
{
get { return fID; }
set { SetPropertyValue<int>("ID", ref fID, value); }
}
public Access(Session session) : base(session) { }
}
My Gate课程:
public partial class Gate : XPLiteObject
{
int fID;
[Key(true)]
public int ID
{
get { return fID; }
set { SetPropertyValue<int>("ID", ref fID, value); }
}
string fName;
[Size(20)]
public string Name
{
get { return fName; }
set { SetPropertyValue<string>("Name", ref fName, value); }
}
}
[Association(@"AccessReferencesGate", typeof(Access))]
public XPCollection<Access> AccessCollection { get { return GetCollection<Access>("AccessCollection"); } }
public Gate(Session session) : base(session) { }
}
任何答案,甚至RTFM链接都将不胜感激!
答案 0 :(得分:1)
像
这样的东西var accesses = new XPQuery<Access>(session);
var result =
from a in accesses
where a.OpenTime == a.GateId.AccessCollection.Max(b => b.OpenTime)
select new { a.GateId.Name, a.Type, a.ReceivedTime };
答案 1 :(得分:0)
DevExpress支持中心的回答,对我有用:
XPView view = new XPView(typeof(Access));
view.AddProperty("Name", "GateId.Name");
view.AddProperty("LatestPass", "[<Access>][GateId = ^.GateId].Max(OpenTime)");
view.AddProperty("Type", "Type");
view.AddProperty("ImportedAt", "ReceivedTime");
view.Criteria = CriteriaOperator.Parse("OpenTime = [<Access>][GateId = ^.GateId].Max(OpenTime)");