我正在使用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; }
}
请告诉我如何在微风中编写上述查询
答案 0 :(得分:2)
您可能需要按如下方式重新编写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
类也包含导航回联系
[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; }
}