views:

64

answers:

3

Hi!

i´m using subsonic 3 trying convert a SQL2008 project to MySQL.

when the projects try execute this LINQ query :

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:

 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.

Any body have any idea about this ?

Many Thanks!

A: 

It looks like mc.Ativo is being read as a UInt64 rather than a 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.

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.

Steve Gilham
Hi Steve, thanks for your response, But the "Ativo" is a property generated by the Subsonic, and it is a Bool type. So the code not leave that i put a int Value like you say. I think that I need to change the Conditional in the Subsonic.Extension.
Myr0
A: 

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 ...

mike123
A: 

Hi Everybody,

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. 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

I hope this help someone! Thanks

Myr0