列名称'userid'无效 [英] Invalid column name 'userid'

查看:450
本文介绍了列名称'userid'无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我首先使用ASP MVC ENTITY FRAMEWORK CODE。我有一个名为Voiture的表,其中包含4个字段。我现在尝试在我的类Voiture.cs中添加一个新的字段UserID:

Hello,

I am using ASP MVC ENTITY FRAMEWORK CODE FIRST. I have a table called "Voiture" which contains 4 fields. I am trying now to add a new field UserID by writing this in my Class Voiture.cs :

[Required]
public String UserId { get; set; }





但我总是遇到这个错误:



but I got always this Error :

<pre lang="c#">Invalid column name 'UserId'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'UserId'.





< b>我尝试了什么:



为了只显示记录用户的相关数据,我在控制器中写了这个:



What I have tried:

in order to show only the data related of the logged User, I wrote this in my Controller :

return View(db.Voitures.Where(a => a.UserId == HttpContext.User.Identity.Name).ToList());

推荐答案

你添加了它到类,但您似乎没有数据库中的匹配列。因此,SQL无法处理您对该列所做的任何请求。

将列添加到数据库...
You added it to the class, but you don't appear to have a matching column in your database. As a result, SQL cannot handle any requests you make to that column.
Add the column to the DB...


完成此操作:为电影模型和表添加新字段| Microsoft Docs [ ^ ]



您将了解正在发生的事情及其发生的原因。
Go through this : Adding a New Field to the Movie Model and Table | Microsoft Docs[^]

You will get the idea about what is happening and why it is happening.


这篇关于列名称'userid'无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆