书呆子晚餐困难

发布于 2024-08-30 16:31:38 字数 641 浏览 3 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

茶花眉 2024-09-06 16:31:38

嘿,我只是在这里推测,但我假设主键应该将自动生成的值属性设置为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文