2017-03-28 11 views
0

아래 코드에서 GetChainsDetails에서 GetChains 메서드의 "내 목록이 필요합니다"로 돌아가고 싶습니다. 성취 방법이나 다른 방법을 모릅니다.내 목록을 도구 설명으로 가져 오려면 어떻게합니까?

public static IEnumerable GetChains(int actGroupid, int dispid) 
    { 
     EEDBEntities db = new EEDBEntities(); 
     var query = from c in db.Chains            
        where c.Activity_Basis.activity_group_id == actGroupid && c.Activity_Basis.discipline_id == dispid 
        select new 
        { 
         ChainID = c.ChainID, 
         ChainDesc = @"<span data-toggle=""tooltip"" title =""" + I WANT MY LIST HERE + @""">" + c.ChainID + "</span>" 
        };    
     return query.ToList(); 
    } 

    public string GetChainDetails(string chainID) 
    { 
     string sStep = null; 
     var chainDetailList = from c in db.Chains_Detail 
           where c.chainID == chainID 
           orderby c.Order 
           select new 
           { 
            Order = c.Order, 
            Step = c.Step 
           }; 
     foreach (var oItem in chainDetailList.ToList()) 
     { 
      sStep = sStep + "\n" + oItem.Order + ": " + oItem.Step; 
     } 
     return sStep; 
    } 
+0

엔티티에 LINQ가 'System.String GetChainDetails (System.String)'메서드를 인식하지 못하고이 메서드를 저장소 식으로 변환 할 수 없습니다. –

+0

EF를 사용하여 데이터를 가져옵니다. 나중에 포맷하십시오. 데이터와 UI 문제를 섞지 마십시오. 훨씬 쉽게. 개인적으로, 나는 자바 스크립트 코드보다 이전에 마크 업을 추가 할 것이다. –

답변

0

메서드 public string GetChainDetails (string chainID)는 정적이 아닙니다. 아마도 이것이 당신이 오류를 범하는 이유입니다. 코드를 정적으로 만들고 코드를 실행하십시오.

class X 
    { 
     public int Property1; 
     public int Property2; 

     public string ChainID; 
     public string MyListToolTipText; 
    } 

    class Y 
    { 
     public string ChainID; 
     public string ChainDesc; 
    } 

, 나는 각 구성원 속성을 수정하고 GetChains를 호출 한 후

class Program 
    { 
    static void Main() 
    { 
     var myResult = GetChains(1, 1); 
     foreach (var result in myResult) 
     { 
      result.ChainDesc = GetChainDetails(result.ChainID); 
     } 
     //you can use either foreach or linq 
     //var m = myResult.Select(result => result = new Y { ChainID = result.ChainID, ChainDesc = GetChainDetails(result.ChainDesc) }); 
    } 

    public static IEnumerable<Y> GetChains(int actGroupid, int dispid) 
    { 
     var Chains = new List<X>(); 
     var query = from c in Chains            
        where c.Property1 == actGroupid && c.Property2 == dispid 
        select new Y 
        { 
         ChainID = c.ChainID, 
         ChainDesc = @"<span data-toggle=""tooltip"" title =""" + c.MyListToolTipText + @""">" + c.ChainID + "</span>" 
        };    
     return query.ToList<Y>(); 
    } 

    public static string GetChainDetails(string chainID) 
    { 
     string sStep = null; 
     var chainDetailList = from c in db.Chains_Detail 
           where c.chainID == chainID 
           orderby c.Order 
           select new 
           { 
            Order = c.Order, 
            Step = c.Step 
           }; 
     foreach (var oItem in chainDetailList.ToList()) 
     { 
      sStep = sStep + "\n" + oItem.Order + ": " + oItem.Step; 
     } 
     return sStep; 
    } 
} 

따라서 메인 코드 :

public static string GetChainDetails(string chainID) 

또한이 방법을 따를 수 있습니다.

+0

예, 죄송합니다. 알아 냈습니다. 하지만이 방법을 사용하여 해답을 얻었습니다. 고맙습니다 –