我试图重新写在C#MVC一个VB.NET的WebForms应用程序。使用实体框架实例化类时,我遇到了其中一个属性的问题。实体框架C#转换INT为bool
我在我的数据库“VATInclusive”,其类型为“诠释”有一列。原来的应用程序隐式转换为“1”或“0”到“真”或“假”,而是试图做这在我的应用程序时,我得到以下错误:
The 'VATInclusive' property on 'Shop' could not be set to a 'System.Int32' value. You must set this property to a non-null value of type 'System.Boolean'.
我不能简单地在其他应用程序使用该表时更改数据库中的类型。我试过使用下面的代码来转换值,但它似乎只返回false,无论数据库是否有“0”或“1”......任何人都可以提出解决方案吗?
[Column("VATInclusive")]
private int _VATInclusive { get; set; }
[NotMapped]
public bool VATInclusive
{
get
{
if (_VATInclusive == 0)
{
return false;
}
else
{
return true;
}
}
set
{
if(_VATInclusive == 0)
{
this.VATInclusive = false;
}
else
{
this.VATInclusive = true;
}
}
}
当你说“我没有任何运气”时,你究竟是什么意思? – furkle 2014-10-26 20:44:31