繁体   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