【发布时间】:2017-05-17 11:56:58
【问题描述】:
有人可以帮帮我吗?按照我的代码和“GelatoProject.exe 中发生‘System.InvalidCastException’类型的未处理异常
附加信息:无法将“System.String”类型的对象转换为“GelatoProject.RecipeVariables”类型。”是消息。
// ...
using (var db = new GelatoProjectDBEntities())
{
RecipeVariables selected =
(RecipeVariables)comboBoxRecipeDetail.SelectedItem;
var results = (from x in db.Recipe_Parameters
select new RecipeVariables
{
Id = x.Id,
RecipeDetail = x.recipeDetail,
Parameter = x.parameter,
RangeDetail = x.rangeDetail,
RangeValue = x.value.ToString()
}
)
.Where(x => x.RecipeDetail == selected.RecipeDetail && x.Parameter == "totalsolids" && x.RangeDetail == "Max")
.FirstOrDefault();
totsolidsRangeMax = decimal.Parse(results.RangeValue);
MessageBox.Show(totsolidsRangeMax.ToString());
}
// ...
class RecipeVariables
{
public int Id { get; set; }
public string NameIngredient { get; set; }
public string Brand { get; set; }
public string LBName { get { return NameIngredient + " - " + Brand;}}
public string RecipeDetail { get; set; }
public string Parameter { get; set; }
public string RangeDetail { get; set; }
public string RangeValue { get; set; }
}
【问题讨论】: