首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有子选择的DevExpress XPO

具有子选择的DevExpress XPO
EN

Stack Overflow用户
提问于 2013-09-22 10:25:30
回答 2查看 2.1K关注 0票数 0

我绞尽脑汁试图用XPO编写下一个MSSQL查询:

代码语言:javascript
复制
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

我的访问表有大约2张磨记录,但只有40个不同的GateId。我想为每扇门选择一条线,如下所示:

门名

....................................................................................

21/T1391-1991超高速机转轨

超门技术产品-超门技术-机转机

我的Access类如下所示:

代码语言:javascript
复制
    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) { }
}

我的门课:

代码语言:javascript
复制
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链接将不胜感激!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-09-23 21:01:42

DevExpress支持中心给我的答案是:

代码语言:javascript
复制
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)");
票数 0
EN

Stack Overflow用户

发布于 2013-09-23 08:31:39

有点像

代码语言:javascript
复制
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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18942797

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档