[英]Successfully extend custom SQL Datatables with aspnet_Membership tables
I have an application which I created using MVC3 and Custom SQL Database with 3 tables: mm_Table1
, mm_Table2
, mm_Jobs
我有一个使用MVC3和自定义SQL数据库创建的具有3个表的应用程序:
mm_Table1
, mm_Table2
, mm_Jobs
I built out the MVC app with a JobsController
and have the respective Views
folder with Create.cshtml
, Delete.cshtml
, Details.cshtml
, Edit.cshtml
and Index.cshtml
我用
JobsController
构建了MVC应用程序,并分别具有Create.cshtml
, Delete.cshtml
, Details.cshtml
, Edit.cshtml
和Index.cshtml
Views
文件夹。
I want to associate mm_Profile
with a User. 我想将
mm_Profile
与用户关联。
After integrating the ASPNET_MEMBERSHIP
Tables into my custom database, I added a UserId
column of Type uniqueidentifier
to mm_Jobs
and created the proper foreign key relationship to aspnet_Users
table ( FK_Jobs_aspnet_Users
) 将
ASPNET_MEMBERSHIP
表集成到我的自定义数据库中之后,我向mm_Jobs
添加了类型uniqueidentifier
的UserId
列,并为aspnet_Users
表( FK_Jobs_aspnet_Users
)创建了适当的外键关系。
I did so and now when I fill out my Jobs form (located in Jobs -> Create.cshtml
) and press the submit button I get the following error : 我这样做了,现在当我填写我的Jobs表单(位于
Jobs -> Create.cshtml
)并按Jobs -> Create.cshtml
按钮时,出现以下错误:
Cannot insert the value NULL into column 'UserId', table 'MovinMyStuff.dbo.Moves'; column does not allow nulls. INSERT fails. The statement has been terminated
The line of code in my JobsController in my Create()
method: 我的JobsController中我的
Create()
方法中的代码行:
Line: 52 db.SaveChanges();
行:52 db.SaveChanges();
How do I update my Create()
to save change and associate the User with the Job, thus pushing the UserId
into the UserId
column in the Jobs
table? 如何更新我的
Create()
来保存更改并将用户与作业相关联,从而将UserId
推送到Jobs
表的UserId
列中? The full create method is given below: 完整的创建方法如下:
[HttpPost]
public ActionResult Create(Job job)
{
if (ModelState.IsValid)
{
db.Moves.Add(job);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(job);
}
I figured this one out. 我想通了。 I had an extra _Layout file in my Shared Folder within my Area.
我所在区域的共享文件夹中有一个额外的_Layout文件。 Apparantly, even upon hiding it the compiler will see this file.
显然,即使将其隐藏,编译器也将看到此文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.