简体   繁体   English

使用aspnet_Membership表成功扩展自定义SQL数据表

[英]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_Table1mm_Table2mm_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.cshtmlDelete.cshtmlDetails.cshtmlEdit.cshtmlIndex.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添加了类型uniqueidentifierUserId列,并为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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM