[英]breezejs SubQuery one-to-many relationship
I am using AngularJS/Breeze and I need to write the ( http://www.breezejs.com/documentation/query-examples ) following SQL using Breeze format: 我正在使用AngularJS / Breeze,并且需要使用Breeze格式在SQL后面编写( http://www.breezejs.com/documentation/query-examples ):
SELECT * FROM CONTACT WHERE ID IN (SELECT contact_id from pharmacy_contact where pharmacy_id='11855'. SELECT * FROM CONTACT WHERE ID IN(从pharmacy_contact中选择contact_id,其中pharmacy_id ='11855'。
My model classes are as follows: 我的模型类如下:
[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; }
}
Please let me know how I should write the above query in breeze 请让我知道如何在微风中编写以上查询
You may want to rephrase your SQL statement as follows: 您可能需要重新编写SQL语句,如下所示:
SELECT * FROM CONTACT inner join pharmacy_contact on ID = contact_id where pharmacy_id=11855.
You can achieve that in breeze: 您可以轻松实现:
var query = EntityQuery.from('CONTACTS')
.expand('pharmacy_contacts')
.where('pharmacy_contacts','any','pharmacy_id', '==', 11855);
Given that you modify the contact
class to include its pharmacy_contacts: 假设您修改了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; }
}
EDIT 编辑
Also the pharmacy_contact
class to include the navigation back to Contact 也是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.