我有以下代码:
public static List<ResponseSupplier> Feza_ReturnSuppliers(string country, string locale, string rtype, string scat, string sscat, string bill, int? comp, double? inc, int? loi, bool? fc, int? hf)
{
string query = string.Format(Queries[SqlQueries.returnquery], country, locale, rtype, scat, sscat, bill, comp, inc, loi, fc, hf);
IList<ExpandoObject> suppliersRaw = DatabaseHelper.MultiResponseComplex(conn, query,
new List<string>
{ "SupID",
"SupName",
"Tlabel",
"Tcode",
"dcstatic",
"dcur",
"dse",
"ltz",
"st",
"isamp",
"minf",
"sf",
"cpt",
"Scoring",
"TrustCoefficient",
"ApiIntegrated",
"fapi"
});
return suppliersRaw.Select(e => new ResponseSupplier
{
SupID = (((dynamic)e).SupID.ToString()) as string,
SupName = (((dynamic)e).SupName) as string,
Tlabel = (((dynamic)e).TierLabel) as string,
Tcode = (int?)(((dynamic)e).Tcode),
dcstatic = (double?)(((dynamic)e).dcstatic),
dcur = (((dynamic)e).dcur) as string,
dse = (((dynamic)e).dse) as string,
ltz = (((dynamic)e).ltz) as string,
st = (((dynamic)e).st) as string,
isamp = (bool?)(((dynamic)e).isamp),
minf = (double?)(((dynamic)e).minf),
sf = (double?)(((dynamic)e).sf),
cpt = (string)(((dynamic)e).cpt),
Scoring = (double?)(((dynamic)e).Scoring),
TrustCoefficient = (double?)(((dynamic)e).TrustCoefficient),
ApiIntegrated = (bool?)(((dynamic)e).ApiIntegrated),
fapi = (bool?)(((dynamic)e).fapi)
}).ToList();
我收到以下错误:'Cannot convert type 'System.DBNull' to 'double?''
这是因为在db中,我可以将Null表示为:“ TrustCoefficient”和“ Scoring”。
我如何克服错误,请注意,当我为null时,我不想获得类似“ 0”的值。那是因为我需要将此列表的结果与另一列表的结果进行比较(并且该列表的参数显示为空)。
有没有一种方法可以转换或解析
Scoring = (double?)(((dynamic)e).Scoring),
TrustCoefficient = (double?)(((dynamic)e).TrustCoefficient),
允许DBNull并在结果中显示Scoring = Null吗?
答案 0 :(得分:0)
尝试一下:
method
您将需要检查每个列的值是否都是DBNull