2014-05-09 5 views
0
다음

는 UI 조인 :를 사용하여 동적 LINQ 도서관은

enter image description here

그리고 이것은 내가 동적 화재로 사용하고 코드입니다 절 : 만든 위의 코드 필터에서

public void bind() 
{ 
string filter = ""; 
      if (!string.IsNullOrEmpty(txtPart.Text)) 
      { 
       filter = filter + "masterinv.inv_item_id = " + txtPart.Text; 
      } 
      if (!string.IsNullOrEmpty(txtDescription.Text)) 
      { 
       if (!string.IsNullOrEmpty(filter)) 
       { 
        filter = filter + " || masterinv.description = " + txtDescription.Text; 
       } 
       else 
       { 
        filter = filter + "masterinv.description = " + txtDescription.Text; 
       } 


      } 
      if (!string.IsNullOrEmpty(txtVendor.Text)) 
      { 
       if (!string.IsNullOrEmpty(filter)) 
       { 
        filter = filter + " || vendor.vendor_name = " + txtVendor.Text; 
       } 
       else 
       { 
        filter = filter + "vendor.vendor_name = " + txtVendor.Text; 
       } 

      } 
InventoryDataContext dc = new InventoryDataContext(InventoryDBContext.GetConnectionstring()); 
       var searchResult = (from masterinv in dc.OMS_REF_Master_Inventories 
            join vendor in dc.OMS_REF_Vendors on masterinv.inv_item_id equals vendor.inv_item_id 
            Where(filter) 
            select new OMS_REF_Master_Inventory 
            { 
             inv_item_id = masterinv.inv_item_id, 
             description = masterinv.description, 
             unit_of_measure = masterinv.unit_of_measure, 
             lot_id = masterinv.lot_id, 
             serial_id = masterinv.serial_id, 
             mfg_id = masterinv.mfg_id, 
             mfg_item_id = masterinv.mfg_item_id, 
             item_status_current = masterinv.item_status_current, 
             cm_unit_cost = masterinv.cm_unit_cost, 
             sync_dte = masterinv.sync_dte 
            }).ToList(); 
        searchResult; 
} 

콤보 상자와 텍스트 필드의 조합을 기준으로 선택. 이러한 하나 개의 필터의 출력

이다 :이 다를 수

masterinv.inv_item_id = 'A' || masterinv.description = 'F' || vendor.vendor_name = 'V' 

가 콤보 값 선택에 의존한다. 콤보 상자의 모든 사례는 BuildQueryFilter 메서드에 있습니다.

문제 :

나는 조항이 가입의 경우 해고 할 수 없습니다입니다. 내가 어디로 잘못 가고 있니?

+1

중단 점을 넣고 마지막 필터 절이 무엇인지 확인하십시오. – tarzanbappa

+0

이것은 내가 얻는 필터입니다 : '% A %'와 같은 masterinv.inv_item_id 또는 'F %'와 같은 masterinv.description 또는 '% V'와 같은 vendor.vendor_name – Sunny

+0

콤보 상자 값 선택에 따라 달라질 수 있습니다. – Sunny

답변

0

linq 쿼리와 함께 %을 사용할 수 없다고 생각합니다.

대신 % 당신은 ... Contains()/StartsWith()/EndsWith()

더 많은 정보를 원하시면,이 참조

How to do SQL Like % in Linq?

How to do a LIKE query with linq?

또는

SQL을 사용하는 방법을 사용할 수 있습니다 ..

where SqlMethods.Like(c.CustomerName, "%/abc/%") 
+0

좋아, 무시하고 간단한 등호를 사용하고 Where 절로 실행할 수 있습니까? – Sunny

+0

예, 할 수 있습니다. 그런 다음 키워드가 필요 없습니다. **처럼 ** 기호 대신 사용할 수 있습니다. – tarzanbappa

+0

지금 내 질문을 업데이트했는지 확인하십시오. – Sunny