简体   繁体   English

如何解决此错误? (LINQ到XML)

[英]How can I resolve this error? (LINQ to XML)

In my project I'm using Entity Framework, I've got a problem in ExamProduced entity, to be especific in Quantify property. 在我使用Entity Framework的项目中,ExamProduced实体存在一个问题,具体来说是Quantify属性。

In my database Quantify property is tinyint datatype, and when VS imported it, it became in byte. 在我的数据库中,Quantify属性是tinyint数据类型,当VS导入它时,它变成了字节数。 VS is notifying me an error that it's unknown for me. VS通知我一个错误,它对我来说是未知的。

Here are the images. 这是图像。

在此处输入图片说明在此处输入图片说明

Yes, there's no explicit conversion from XAttribute to byte . 是的,没有从XAttributebyte显式转换。 You'd probably be okay with: 您可能会同意:

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

The (int) part will apply the explicit XAttribute to int conversion ; (int)部分将显式XAttribute应用于int转换 the (byte) part will perform a narrowing int to byte conversion. (byte)部分将执行从intbyte的缩小转换。 You may want to make this checked so that you'll get an exception if the attribute is "500" for example. 您可能需要checkedchecked以便在属性为“ 500”的情况下获得异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM