【问题标题】:Error on updating record with Subsonic (MySql)使用 Subsonic (MySql) 更新记录时出错
【发布时间】:2015-03-06 13:01:00
【问题描述】:

我正在使用以下代码更新表中的记录:

var usr = test.Data.user.SingleOrDefault(y => y.id == 1);
usr.name = "test";
usr.Save();

检索该行工作正常,但是当我 Save() 时,我在文件 database.cs 第 412 行中遇到 NullReferenceException,代码如下:

Constraint c = new Constraint(ConstraintType.Where, tbl.PrimaryKey.Name)
               {
                   ParameterValue = settings[tbl.PrimaryKey.Name],
                   ParameterName = tbl.PrimaryKey.Name,
                   ConstructionFragment = tbl.PrimaryKey.Name   
               };

tbl.PrimaryKey 在这个地方为空,我认为这可能是问题所在。我确实在表的 id 字段上设置了主键。我还在 Visual Studio 2010 上使用来自 git repo 的最新版本。有人知道可能是什么问题吗?

编辑:

通过在此线程中使用 nosynchro 的答案修复:

SubSonic 3 and MySQL, removing underscore from column name in CleanUp() method causes exceptions when using property in linq-query

希望这也能在 git repo 中得到修复。

【问题讨论】:

    标签: c# .net mysql subsonic subsonic3


    【解决方案1】:

    我是亚音速的新手,当我尝试更新从数据库检索到 gridview 的数据时,我遇到了同样的错误。我使用了从这个网站获得的一段代码。

    代码:

       Emptab emp = Emptab.FetchById(txtId.Text);
    
       emp.Fname = txtFirstName.Text;
       emp.Mname = txtMiddleName.Text;
       .....
       emp.Save();
    

    这里,Emptab== 我的表的类,(Fname,Mname)==表的列名

    【讨论】:

    • 我最终放弃了亚音速。有很多错误(至少对于 SQLite),查找文档时遇到了麻烦,而且看起来该项目不再受到真正的支持。我最终使用了system.data.sqlite.org
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-17
    • 1970-01-01
    • 2010-09-14
    • 1970-01-01
    • 2015-08-24
    • 1970-01-01
    • 2015-04-10
    相关资源
    最近更新 更多