书呆子晚餐困难
我对 NerdDinner 教程的 Create 方法有疑问,顺便说一句,该方法非常好。
正如您在这里看到的 http://nerddinnerbook.s3.amazonaws.com/Part5.htm 在Create方法中,他去掉了aspx页面的ID字段。
我也这样做了,但我无法添加任何晚餐,因为我遇到了主键违规。
NerdDinner 是如何控制每顿晚餐的 id 的?我修改了教程,但在 SQL 数据库上看不到任何对身份字段的引用。
我什至创建了一个方法来获取表中的最高 id:
public int GetHighestDinnerId()
{
int resultado = (from dinner in dataContext.Dinners
select dinner.DinnerId).Max();
return resultado;
}
这也不起作用。
有什么想法吗?
谢谢
I'm having a problem with the Create method of the NerdDinner tutorial, which is very good BTW.
As you can see here http://nerddinnerbook.s3.amazonaws.com/Part5.htm in the Create method, he removed the ID field of the aspx page.
I did that too, but I cannot add any dinners because I get a primary key violation.
How is NerdDinner controlling the ids of each dinner? I revised the tutorial and could not see any references to identity fields on SQL database.
I even created a method to get me the highest id in the table:
public int GetHighestDinnerId()
{
int resultado = (from dinner in dataContext.Dinners
select dinner.DinnerId).Max();
return resultado;
}
which does not work either.
Any thoughts?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嘿,我只是在这里推测,但我假设主键应该将自动生成的值属性设置为 true,这样您就不必显式设置它,它会在插入时为您生成。您应该能够在 dbml 中进行配置。
编辑:刚刚浏览了 NerdDinner 教程,如果您查看步骤 2,它会讨论将 ID 列设置为标识列,以便该值是自动生成的,这可能就是您想要配置它的位置。
Heya, I'm just speculating here but I assume that the primary key should have the Auto-generated value property set to true so you don't have to explicitly set it, it gets generated for you on insert. You should be able to configure that within the dbml.
EDIT: Just looked through the NerdDinner tutorial and if you look at step 2, it talks about setting the ID column as an identity column so the value is auto-generated which is probably where you want to configure it.