当前表添加新数据时为相关表创建Id MVC 5

发布于 2025-01-12 01:35:52 字数 605 浏览 5 评论 0原文

我有一个注册后需要填写的申请表,我有一个用户和一个相关的申请表。

中创建新的 ID

我希望在用户注册并将数据添加到用户表后,在应用程序表用户表

在此处输入图像描述

应用表

在此处输入图像描述

这里我希望在数据输入时自动创建新ID添加到用户表(与所选列一样)

我用于注册的代码

public void StudentAdd(T p)
{
    c.Set<T>().Add(p);
    c.SaveChanges();
}

registrationRepository.StudentAdd(user);

我该如何实现? 先感谢您

I have an application that needs to be filled in after registration, I have a User and a related Application table.

I want that after user is registered and the data was added to the User table, new Id was created in the Application table

User table

enter image description here

Application table

enter image description here

Here I want new ID to be created automatically when data is added to User table (as it is with selected column)

The code I used for registration

public void StudentAdd(T p)
{
    c.Set<T>().Add(p);
    c.SaveChanges();
}

registrationRepository.StudentAdd(user);

How can I implement that?
Thank you in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

笨笨の傻瓜 2025-01-19 01:35:52

更新表应用程序中的 DDL,声明 Id 列为自动增量或串行,这样做您不需要传递 id,它将自动创建。

Update the DDL in the table Application declare that Id column as Auto Increment or Serial, doing so you don't need to pass the id it will be automatically created.

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