The property "x" in "y" cannot be set to "System.Decimal". You must set this property to a non-zero value of type 'System.Boolean'

I have a MySQL stored procedure that selects data from a specific table named tuser.

I use EntityFramework6, so I defined the result of the procedure as an object tuser.

enter image description here

When I use a procedure in C # code, the following exception is thrown:

The "bIsActive" property on "tuser" cannot be set to "System.Decimal". You must set this property to a non-zero value of type "System.Boolean".

I cannot understand the connection between the action that I want to do and the exception created.

Definition of a table in a database:

CREATE TABLE `tuser` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`sUserName` varchar(45) DEFAULT NULL,
`sUserNameMail` varchar(45) DEFAULT NULL,
`sMail` varchar(45) DEFAULT NULL,
`bIsActive` bit(1) DEFAULT b'1')
 ENGINE=InnoDB AUTO_INCREMENT=2225 DEFAULT CHARSET=utf8;

bIsActive ef:

enter image description here

:

CREATE DEFINER=``@`` PROCEDURE `GetActiveUsers`()
BEGIN
  select u.* from tuser u
  where u.bIsActive=true;
END

:

List<tuser> list = Context.GetActiveUsers().ToList();

GetActiveUsers ( ):

public virtual ObjectResult<tuser> GetActiveUsers()
{    
   return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<tuser>("GetActiveUsers");
}
+4
2

, .

, , tuser , .

+1

, bIsActive decimal - :

List<tuser> list = Context.GetActiveUsers().ToList();

, - , , , .

...

public virtual ObjectResult<tuser> GetActiveUsers()
{    
    return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<tuser>("GetActiveUsers");
}

... ...

public virtual ObjectResult<tuser> GetActiveUsers()
{
    try
    {
        Stringbuilder sb = new Stringbuilder();

        IObjectContextAdapter a = ((IObjectContextAdapter)this); // Breakpoint this line and F11 step through the code, looking at local variables as you go

        sb.AppendLine(", a: " + a.ToString());

        var b = a.ObjectContext;

        sb.AppendLine(", b: " + b.ToString());

        var c = b.ExecuteFunction<tuser>("GetActiveUsers");

        sb.AppendLine(", c: " + c.ToString());

        MessageBox.Show("No exception: (" + sb.ToString() + ")");

        return c;

    }
    catch(Exception ex)
    {
        MessageBox.Show("Exception: (" + ex.message + ex.stacktrace + ")");

    }

}

, , , . , , StackTrace, .

  • MessageBox

, , GetActiveUsers.

MySql? Workbench MySql ? .

-3

Source: https://habr.com/ru/post/1679866/


All Articles