我该如何解决这个错误? (LINQ to XML)

时间:2011-12-15 22:03:49

标签: c# linq entity-framework linq-to-xml

在我的项目中,我正在使用Entity Framework,我在ExamProduced实体中遇到了一个问题,特别是在Quantify属性中。

在我的数据库中,Quantify属性是tinyint数据类型,当VS导入它时,它变成了byte。 VS正在通知我一个我不知道的错误。

以下是图片。

enter image description here enter image description here

1 个答案:

答案 0 :(得分:3)

是的,没有从XAttributebyte的明确转换。你可能没问题:

Quantify = (byte) (int) objective.Attribute("Quantify")

(int)部分将应用explicit XAttribute to int conversion; (byte)部分将执行缩小intbyte转化。您可能想要生成此checked,以便在属性为“500”时获得异常。