我有一个具有可空属性的自定义类型,我试图从SQL中的可为空的列进行投影。我总是像这样得到'missmethodexception':
{"Method not found: 'Void MyType.set_Number(System.Nullable`1<Int32>)'."}
尝试使用可以为空的自动属性投影到自定义类型时是否存在问题?代码如下所示:
public class MyType {
public string Name {get;set;}
public decimal Value { get; set;}
public int? Number { get; set;}
}
Dictionary<int, CustomType> dict;
dict = (from t in table
select new {
id = av.Account.Id,
mt = new MyType { Name = t.Name, Value = t.Value, Number = t.Number }
}).ToDictionary(item => item.id, item => item.mt);