我正在尝试查询多个表并将查询保存为全局字典以供进一步处理。我尝试了以下内容,但是我在字典中得到了类名而不是值。请查看我的错误以及在todictionary
查询上阅读更多内容的位置?
public class linqtosql
{
public Dictionary<int, MC_VARIABLES> dctMC = new Dictionary<int, MC_VARIABLES>();
public class MC_VARIABLES
{
public int ID { get; set; }
public int UDLY_LAST { get; set; }
public int STRIKE { get; set; }
public decimal SKEW_A { get; set; }
public decimal SKEW_B { get; set; }
public double SKEW_C { get; set; }
}
public void GET_DATA()
{
var qryBOOK = from B in Globals.DATA.BOOKs
from O in Globals.DATA.OPTIONs
from U in Globals.DATA.UDLies
from S in Globals.DATA.SKEWs
where B.CONTRACT == O.CONTRACT
where O.UDLY_SYMBOL == U.UDLY_SYMBOL
where O.CONTRACT == S.CONTRACT
select new MC_VARIABLES
{ ID = B.ID, STRIKE = (int)B.STRIKE, SKEW_A = (decimal)S.SKEW_A };
dctMC = qryBOOK.ToDictionary(x => x.ID, x => x);
foreach (KeyValuePair<int, MC_VARIABLES> KVP in dctMC)
{
var key = KVP.Key;
var item = KVP.Value.SKEW_A;
}
}
}
答案 0 :(得分:1)
它应该是x => x
而不是x => MC_VARIABLES
,在这种情况下,x的类型为MC_VARIABLES。
qryBOOK.ToDictionary(x => x.ID, x => x)