mysql - 将 mysql tinyint 与 subsonic 3 和 datagridview 绑定(bind)时出现问题

标签 mysql subsonic subsonic3

我使用 subsonic 创建了一个数据层。但是,当我选择数据时,出现以下异常。

    System.ArgumentException was unhandled
  Message="Object of type 'System.Boolean' cannot be converted to type 'System.SByte'."
  Source="mscorlib"
  StackTrace:
       at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
       at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
       at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
       at SubSonic.Extensions.Database.Load[T](IDataReader rdr, T item, List`1 ColumnNames)
       at SubSonic.Extensions.Database.ToEnumerable[T](IDataReader rdr, List`1 ColumnNames)
       at SubSonic.Linq.Structure.DbQueryProvider.Execute[T](QueryCommand`1 query, Object[] paramValues)
       at lambda_method(ExecutionScope )
       at SubSonic.Linq.Structure.DbQueryProvider.Execute(Expression expression)
       at SubSonic.Linq.Structure.QueryProvider.System.Linq.IQueryProvider.Execute(Expression expression)
       at SubSonic.Linq.Structure.Query`1.GetEnumerator()
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
       at TorontoTrader.Data.Ver2.ninjascan.Find(Expression`1 expression) in E:\TradingTools\CODE\TorontoTraderDataVer2\TorontoTraderDataVer2\ActiveRecord.cs:line 4148
       at TorontoTraderAlerts.Form1.Form1_Load(Object sender, EventArgs e) in E:\TradingTools\CODE\TorontoTraderDataVer2\TorontoTraderAlerts\Form1.cs:line 24
       at System.Windows.Forms.Form.OnLoad(EventArgs e)
       at System.Windows.Forms.Form.OnCreateControl()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.WmShowWindow(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ContainerControl.WndProc(Message& m)
       at System.Windows.Forms.Form.WmShowWindow(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
       at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Control.set_Visible(Boolean value)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at TorontoTraderAlerts.Program.Main() in E:\TradingTools\CODE\TorontoTraderDataVer2\TorontoTraderAlerts\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

the code segment wher its throwing it is 

public static IList<ninjascan> Find(Expression<Func<ninjascan, bool>> expression) {

            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }

the column in Mysql is TinyInt (Length=1)

dunno how to fix it.

最佳答案

在你的 mysql 连接字符串中添加一个“Treat Tiny As Boolean”参数,例如:

Server=srv;Database=db;Uid=user;Pwd=pass;Treat Tiny As Boolean=true;

这应该强制 MySQL.Data 连接器为 TINYINT(1) 返回 true 或 false。

mysql 文档声称这似乎是默认行为

http://dev.mysql.com/doc/refman/5.1/en/connector-net-connection-options.html

但我很确定 false 是早期版本中的默认值。

关于mysql - 将 mysql tinyint 与 subsonic 3 和 datagridview 绑定(bind)时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3452326/

相关文章:

mysql - 如何优化我的查询(排名查询)?

java - GlassFish 5 中的 2PC 事务(交叉事务)

c# - 亚音速交易错误

subsonic - SubSonic 3.0 中的 SQL View

open-source - SubSonic 的许可证是什么?

java - 从更新的 SQL 数据库刷新 JavaFX 场景?

php - WordPress wpdb 中的 AND 和 OR 查询

.net - 与 Subsonic 的一对一关系

.net - SubSonic 3.0 中的关系和延迟加载

mysql - SubSonic 3 和 MySQL,在 CleanUp() 方法中从列名中删除下划线会导致在 linq-query 中使用属性时出现异常