代码之家  ›  专栏  ›  技术社区  ›  petrosmm Saeed Neamati

服务堆栈自动查询联接使用

  •  2
  • petrosmm Saeed Neamati  · 技术社区  · 7 年前

    在阅读了文档之后,我不确定,但我得出的结论是,在创建querydb时,您不能选择要连接的列吗?而我的印象是,你一定有反对复制的对象吗?不能复制到常规对象或动态对象?

    public class SampleAutoQueryDb : QueryDb<MailResponseDetailOrm, object>, ILeftJoin<MailResponseDetailOrm, MailResponseOrm> { }

    有人能提供任何有关加入我的mailresponseorm到mailresponsedetailorm的见解吗?mailresponsedetailorm有5个字段,即 Email 地址。我想让mailresponseorm加入 电子邮件 也。另外,为了更好的度量,我不想更改任何一个列名。我需要创建一个自定义实现还是一个服务来实现这一点?

    更新

    以下是我的代码:

            [Alias("MailReportsDetail")]
            public class MailResponseDetailOrm
            {
                public string Email { get; set; }
    
                public int ID { get; set; }
    
                [Alias("RespDate")]
                public DateTime? AddedDateTime { get; set; }
    
                [Alias("DLReport")]
                public string Action { get; set; }
    
                public string ActionDetail { get; set; }
    
                public string IP { get; set; }
    
                public string UserAgent { get; set; }
    
                public string EmailReferrer { get; set; }
            }
    
        [Alias("MailReports")]
        public class MailResponseOrm
        {
            public int ID { get; set; }
    
            public string Email { get; set; }
    
            public string Address1 { get; set; }
    
            public string Address2 { get; set; }
    
            public string City { get; set; }
    
            public string Company { get; set; }
    
            public string Contact { get; set; }
    
            public string Country { get; set; }
    
            [Alias("LastMail")]
            public DateTime? ModifiedDateTime { get; set; }
    
            [Alias("LastReport")]
            public string Action { get; set; }
    
            public DateTime? OptOut { get; set; }
    
            public string Part { get; set; }
    
            public string Phone { get; set; }
    
            public string PostalCode { get; set; }
    
            public string Source { get; set; }
    
            public string State { get; set; }
    
            public string Title { get; set; }
    
            #region Obsolete
    
            [Obsolete]
            public string Class { get; set; }
    
            [Obsolete]
            public string IP { get; set; }
    
            #endregion
        }
    
    public class SampleAutoQueryDb : QueryDb<MailResponseDetailOrm> { }
    
    public class MyQueryServices : Service
    {
        public IAutoQueryDb AutoQuery { get; set; }
    
        // Override with custom implementation
        public object Any(SampleAutoQueryDb query)
        {
            var q = AutoQuery.CreateQuery(query, base.Request);
            q.Join<MailResponseDetailOrm, MailResponseOrm>((x, y) => x.Email == y.Email)
                // .Select<MailResponseDetailOrm, MailResponseOrm>((x, y) => new { x.ID, y.Email })
                ;
            return AutoQuery.Execute(query, q);
        }
    }
    
    2 回复  |  直到 6 年前
        1
  •  2
  •   mythz    7 年前

    AutoQuery中的联接需要使用 OrmLite's Joins Reference conventions 并且所有自动查询服务的结果都以类型化的DTO返回,默认情况下,该DTO是正在查询的表,或者可以使用 QueryDb<From,Into> 要返回的基类 custom result of columns from multiple joined tables .

    你需要使用 Custom AutoQuery Implementation 或者您自己的服务实现,如果您需要除此之外的定制,例如:

    public class SampleAutoQueryDb : QueryDb<MailResponseDetailOrm> { }
    
    public class MyQueryServices : Service
    {
        public IAutoQueryDb AutoQuery { get; set; }
    
        // Override with custom implementation
        public object Any(SampleAutoQueryDb query)
        {
            var q = AutoQuery.CreateQuery(query, base.Request);
            q.Join<MailResponseDetailOrm,MailResponseOrm>((x, y) => x.Email == y.Email);
            return AutoQuery.Execute(query, q);
        }
    }
    
        2
  •  2
  •   Bob K    7 年前

    //在类中未专门设置的字段名上联接2个对象的查询。

    var q = Db.From<MailResponseDetailOrm>().Join<MailResponseDetailOrm>(x,y) => x.Email = y.Email);
    

    //运行查询

    var results = Db.Select(q);
    
    推荐文章