【问题标题】:LINQ-to-SQL get Primary Key from TableLINQ-to-SQL 从表中获取主键
【发布时间】:2013-12-04 21:43:40
【问题描述】:

我在弄清楚为什么在使用此代码时收到NullReferenceException 时遇到了一些麻烦:

entityCustomer customer = new entityCustomer { 
                              firstName = txtFName.Text, 
                              lastName = txtLName.Text, 
                              homeAddress = txtAddress.Text, 
                              phoneNumb = txtPhone.Text, 
                              emailAddress = txtEmail.Text 
                          };

custTable.InsertOnSubmit(customer);
dc.SubmitChanges();

我在InsertOnSubmit 上收到错误消息。这是我的实体类:

http://pastebin.com/49RtamPN

如您所见,我尝试关注https://stackoverflow.com/a/788402/2416047,但仍然没有运气。

我做错了什么?

【问题讨论】:

  • 附注 - 我们使用 PascalCase 来表示属性和类名
  • 是否已实例化 custTable?您可能需要提供比这更多的代码才能让我们进行调试。

标签: c# sql sql-server linq linq-to-sql


【解决方案1】:

您的custTable 变量、参数、属性或字段为空。 在调用它的任何成员之前,您需要为其分配一个值。

【讨论】:

  • 我意识到我错过了实例化 custTable。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-19
  • 2013-03-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多