[LINQ]InsertOnSubmit NullReferenceException
我在使用 LinqToSql 时遇到了一个相当烦人的问题。我创建了一个从 DataContext 中的类派生的类。
问题是,一旦我使用“InsertOnSubmit(this);”在这个派生类上,我得到一个 NullReferenceException。
我见过一些人有同样的问题。然而,他们使用了自定义构造函数,并通过像此线程一样调用“:this()”解决了问题 http://social.msdn.microsoft.com/Forums/en-US/linqprojectgeneral/thread/0cf1fccb-6398-4f16-920b-adef9dc4ac9f
不同之处在于我使用默认构造函数,这会导致调用基本构造函数,因此应该不会有任何问题!
有人可以帮我解决这个问题吗,开始变得烦人了!
谢谢 :)
I have a rather annoying issue with LinqToSql. I have created a class that is derived from the class in the DataContext.
The problem is that as soon as I use "InsertOnSubmit(this);" on this derived class I get a NullReferenceException.
I've seen some people with the same issue. However they've used a custom constructor and solved the issue by calling ": this()" like this thread http://social.msdn.microsoft.com/Forums/en-US/linqprojectgeneral/thread/0cf1fccb-6398-4f16-920b-adef9dc4ac9f
The difference is that I use a default constructor which causes the base constructor to be called so there should not be any problem!
Could someone please help me with this, starts to get annoying!
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一种方法: https://stackoverflow.com /....
如果您只想预先填充一些字段,替代方案可能是:
This is one way: https://stackoverflow.com/....
If you just want to pre-populate some fields, an alternative might be: