簡體   English   中英

breezejs SubQuery一對多關系

[英]breezejs SubQuery one-to-many relationship

我正在使用AngularJS / Breeze,並且需要使用Breeze格式在SQL后面編寫( http://www.breezejs.com/documentation/query-examples ):

SELECT * FROM CONTACT WHERE ID IN(從pharmacy_contact中選擇contact_id,其中pharmacy_id ='11855'。

我的模型類如下:

[Table("pharmacy_contact")]
public class PharmacyContact
{
    [Key]
    public int Id { get; set; }
    public int? PharmacyId { get; set; }
    public int? ContactId { get; set; }

}

[Table("contact")]
public class Contact
{
    [Key]
    public int Id { get; set; }
    public string First_Name { get; set; }
    public string Last_Name { get; set; }
    public string Title { get; set; }
    public string Phone { get; set; }
    public string Extn { get; set; }
    public string Fax { get; set; }
    public string Email { get; set; }
    public string Contact_Daytime { get; set; }
    public string Contact_Method { get; set; }
    public string Contact_Type { get; set; }

}

請讓我知道如何在微風中編寫以上查詢

您可能需要重新編寫SQL語句,如下所示:

SELECT * FROM CONTACT inner join pharmacy_contact  on ID = contact_id where pharmacy_id=11855. 

您可以輕松實現:

 var query = EntityQuery.from('CONTACTS')
    .expand('pharmacy_contacts')
    .where('pharmacy_contacts','any','pharmacy_id', '==', 11855);

假設您修改了contact類別以包括其pharmacy_contacts:

  [Table("contact")]
public class Contact
{
    [Key]
    public int Id { get; set; }
    public string First_Name { get; set; }
    public string Last_Name { get; set; }
    public string Title { get; set; }
    public string Phone { get; set; }
    public string Extn { get; set; }
    public string Fax { get; set; }
    public string Email { get; set; }
    public string Contact_Daytime { get; set; }
    public string Contact_Method { get; set; }
    public string Contact_Type { get; set; }
    public  ICollection<pharmacy_contact> pharmacy_contacts { get; set; }

}

編輯

也是pharmacy_contact類,包括導航回Contact

[Table("pharmacy_contact")]
public class PharmacyContact
{
    [Key]
    public int Id { get; set; }
    public int? PharmacyId { get; set; }
    [ForeignKey("Contact")]
    public int? ContactId { get; set; }
    public contact contact { get; set; }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM