contact_list 테이블과 Many-Many 관계를 갖는 CustomerGroup 테이블이 있습니다. 세 번째 테이블 CustomerGroupContact 두 테이블의 기본 키가 있습니다. 나는 모양을 객체를 생성하기 위해 두 테이블을 조인하기 위해 노력하고있어Linq와 many to many relationship 쿼리
public class Contact_List
{
[Key]
public int Contact_List_Code { get; set; }
public int Customer_Code { get; set; }
public string First_Name { get; set; }
public string Last_Name { get; set; }
public string Contact_No { get; set; }
}
:
public class CustomerGroup
{
public CustomerGroup()
{
CustomerGroupContacts = new HashSet<CustomerGroupContact>();
}
[Key]
public int Customer_Group_Code { get; set; }
public int Customer_Code { get; set; }
public string Customer_Group_Name { get; set; }
public virtual ICollection<CustomerGroupContact> CustomerGroupContacts { get; set; }
}
여기처럼 Contact_List 모델이 어떻게 표시되는지를 보여줍니다 : 여기
는 CustomerGroup 테이블의 모습입니다 아래 모델 :public class Contacts
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string ContactNo { get; set; }
public string GroupName { get; set; }
}
올바른 쿼리 문을 사용하는 데 어려움을 겪고 있습니다. customer_code 속성을 기반으로 테이블을 조인합니다. 도움을 주시면 감사하겠습니다.
나는 당신이 ORM을 사용하고, 일부 재산에'[키]'속성이 참조 (같은 엔티티 프레임 워크)? –
http://pastebin.com/gYkTmKyA. 이것은 내가 지금까지 가지고있는 것이지만 너무 노골적으로 잘못되었다는 것을 알고있다. – psyoptica
@RemyGrandin 예 코드 첫 번째 모델에서 EF를 사용하고있다. – psyoptica