简体   繁体   English

亚超音速3-无法将类型为'System.UInt64'的对象转换为类型为'System.Boolean'

[英]Subsonic 3 - Object of type 'System.UInt64' cannot be converted to type 'System.Boolean'

i´m using subsonic 3 trying convert a SQL2008 project to MySQL. 我正在使用亚音速3试图将SQL2008项目转换为MySQL。

when the projects try execute this LINQ query : 当项目尝试执行此LINQ查询时:

public IQueryable<Marca> SelecionaMarcas()
        {
            try
            {                

                return (from mc in _db.Marcas
                        where mc.Ativo == true
                        orderby mc.NomeMarca
                        select mc);
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

returns this error : 返回此错误:

Object of type 'System.UInt64' cannot be converted to type 'System.Boolean'

in the SubSonic.Extensions Database.cs line 193: 在SubSonic.Extensions Database.cs第193行中:

 if (val.GetType().IsAssignableFrom(valueType)){
                            currentProp.SetValue(item, val, null);
                        } else {
                            currentProp.SetValue(item, rdr.GetValue(i).ChangeTyp

that is the table of my Database: 那是我的数据库表:

CREATE TABLE `marca` (
  `ID_Marca` int(4) NOT NULL AUTO_INCREMENT,
  `NomeMarca` varchar(100) COLLATE utf8_unicode_ci NOT NULL DEFAULT '1',
  `Ativo` bit(1) NOT NULL,
  `LogoMarca` varchar(250) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`ID_Marca`)
) ENGINE=InnoDB AUTO_INCREMENT=132 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

in Debug Mode i found the error is the Ativo Field. 在调试模式下,我发现错误是Ativo字段。

Any body have any idea about this ? 有谁对此有任何想法?

Many Thanks! 非常感谢!

It looks like mc.Ativo is being read as a UInt64 rather than a bool . 看起来mc.Ativo被读为UInt64而不是bool Alas, I don't know enough about SubSonic or how you are invoking it to tell what needs to be changed to make the single-bit column map to a bool as you wish. Sub,我对SubSonic知之甚少,或者您如何调用它以告诉您需要进行哪些更改才能使一位列映射到bool

To fix the symptom, if not the underlying problem of the returned field type, changing the 若要解决此症状,如果不是返回的字段类型的根本问题,请更改

where mc.Ativo == true

to

where mc.Ativo != 0 

would do what you want. 会做你想要的。

I think i had come across this problem before as well, subsonic doesn't like fields that have unassigned flag set. 我想我之前也遇到过这个问题,亚音速不喜欢设置了未分配标志的字段。 It could prob easily fixed by finding the place in the template where type matching occures between C# and DB ... 通过查找模板中C#和DB之间发生类型匹配的位置,可以很容易地解决该问题。

Thanks for all help, but i did a modification in the SubSonic Core to correct thus error, in the extensions.Database.cs i put one conditional if the Name of ProportyType is "System.Boolean" i use the GetBoolean Method else i use GetValue. 感谢所有帮助,但我在SubSonic Core中进行了修改,以纠正extensions.Database.cs中的错误,如果ProportyType的名称为“ System.Boolean”,则我使用一个条件,我使用GetBoolean方法,否则使用GetValue。 。 There is the code modified below: 有下面修改的代码:

                    //TO Adjust the BUG Boolean with UInt64.
                    Type valueType = null;
                    if (currentProp.PropertyType.FullName == "System.Boolean")
                        valueType = rdr.GetBoolean(i).GetType();
                    else
                        valueType = rdr.GetValue(i).GetType();

(Line 174) Before the ValueType Conditional (第174行)在ValueType条件之前

I hope this help someone! 希望对您有所帮助! Thanks 谢谢

暂无
暂无

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

相关问题 无法将“System.Byte”类型的对象强制转换为“System.UInt64”类型 - Unable to cast object of type 'System.Byte' to type 'System.UInt64' 类型“System.Func`2[T,System.Boolean]”的表达式不能用于返回类型“System.Boolean” - Expression of type 'System.Func`2[T,System.Boolean]' cannot be used for return type 'System.Boolean' 无法将属性“X”中的字符串“False”转换为“System.Boolean”类型的对象 - Cannot convert string 'False' in attribute 'X' to object of type 'System.Boolean' linq查询无法将类型为“ System.Boolean”的对象转换为类型为“ System.String”的对象 - linq query getting Unable to cast object of type 'System.Boolean' to type 'System.String' “System.Int32”类型的对象无法转换为“System.UInt32&”类型 - Object of type 'System.Int32' cannot be converted to type 'System.UInt32&' 无法将类型为“ System.Boolean”的对象转换为类型为“ System.String”的对象 - Unable to Cast Object of type 'System.Boolean' to type 'System.String' 无法将“System.String”类型的 object 转换为“System.Boolean.Net Core MVC” - Unable to cast object of type 'System.String' to type 'System.Boolean .Net Core MVC 无法将“System.Int32”类型的 object 转换为“System.Boolean”类型。 - Unable to cast object of type 'System.Int32' to type 'System.Boolean'.' 怎么把System.Byte []转换成System.UInt64 []? - How convert System.Byte[] To System.UInt64[]? C#Json.Net:{“无法将类型为&#39;System.Boolean [,]&#39;的对象转换为类型为&#39;System.Collections.Generic.ICollection`1 [System.Boolean]&#39;。”} - C# Json.Net: {“Unable to cast object of type 'System.Boolean[,]' to type 'System.Collections.Generic.ICollection`1[System.Boolean]'.”}
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM