3
익명 유형의 linq 표현식에서 사전의 TryGetValue()
을 사용할 수 없습니다.익명 형식의 linq 표현식에서 TryGetValue()
Dictionary<string, string> dict = new Dictionary<string, string>()
{
{"1", "one"},
{"2", "two"},
{"3", "three"}
};
public string getValueByKey(string value)
{
string sColumnType = "";
dict.TryGetValue(value, out sColumnType);
return sColumnType;
}
[WebMethod]
public string getData(string name)
{
var result = (from z in myObject
where z.name == name
select new
{
a = z.A,
b = z.B,
c=getValueByKey(z.C) //fails there
}).ToList();
return new JavaScriptSerializer().Serialize(result);
}
사전에 키로 값을 얻을 수있는 방법을 알려주십시오.
어떤 오류 메시지가 표시됩니까? – Luiscencio
@Luiscencio : Visual Studio에서 구문 오류로 빨간색 밑줄이 그어지지 않았습니다. 하지만 디버깅을 나는 이런 식으로 잡는다 : ("메시지": "LINQ to Entities식이 \"System.String getValueByKey (System.String) \ "메서드를 인식하지 못하므로 식으로 변환 할 수 없습니다. 리포지토리. ","StackTrace ":"System.Data.Objects. – loviji
은 dis와 관련된 무언가를 물었습니다 : http://stackoverflow.com/questions/2466495/why-do-linq-to-entities-does- 고맙습니다 - 특정 - 방법을 – Luiscencio