简体   繁体   English

我如何 map SQL 服务器表的一列,以数字开头(列名称:2DBIT),到 ASP.NET MVC 项目(存储过程?

[英]How can I map a column of a SQL Server table, beginning with a number (name of the column:2DBIT), to an ASP.NET MVC project (stored procedure) CRUD?

I have a table in SQL Server with some columns.我在 SQL 服务器中有一个表,其中包含一些列。 I wrote some stored procedures.我写了一些存储过程。 I have loaded those tables and stored procedures on an ASP.NET MVC project with Visual Studio, with first database.我已经使用 Visual Studio 在 ASP.NET MVC 项目上加载了这些表和存储过程,并带有第一个数据库。 Visual Studio produced the crud for this table, that is working with the default Entity Framework. Visual Studio 为这个表生成了 crud,它与默认的实体框架一起工作。

But my job is to use stored procedures for the crud.但我的工作是使用存储过程来处理杂物。 There my problems began.我的问题开始了。

The problem really is that one of the columns has a number at the beginning of its name: 2DBIT (the job doesn't allow me to change the column name).问题实际上是其中一列的名称开头有一个数字: 2DBIT (该作业不允许我更改列名)。

I debug the code and get an exception:我调试代码并得到一个异常:

System.Data.Entity.Core.EntityCommandExecutionException: 'The data reader is incompatible with the specified 'LotContext_NS.IS_MCC6CoaterLot'. System.Data.Entity.Core.EntityCommandExecutionException: '数据读取器与指定的 'LotContext_NS.IS_MCC6CoaterLot' 不兼容。 A member of the type, 'C2DBit', does not have a corresponding column in the data reader with the same name.'类型的成员“C2DBit”在数据读取器中没有同名的对应列。

LotContext is my context, and IS_MCC6CoaterLot is the table. LotContext是我的上下文, IS_MCC6CoaterLot是表。

I think the problem ist, that the automatically generated code changes the code of the mapped IS_MCC6CoaterLot.cs on the column with: C2DBIT .我认为问题在于,自动生成的代码将列上映射的IS_MCC6CoaterLot.cs的代码更改为: C2DBIT

The compiler doesn't find the given column in the database and throws the error.编译器在数据库中找不到给定的列并抛出错误。

What can I do to solve this problem?我能做些什么来解决这个问题? Is changing the column name the only opportunity?更改列名是唯一的机会吗?

The CRUD is running with normal entity FW. CRUD 与普通实体 FW 一起运行。 If I adjust the code with the stored procedures, I have that problem.如果我用存储过程调整代码,我就会遇到这个问题。

//the mapped class of the table
public partial class IS_MCC6CoaterLot
{
  public Nullable<bool> C2DBit { get; set; }

}

//the action of the controller
public ActionResult Index()
{
    using (LotContext Db = new LotContext())
    {
        List<IS_MCC6CoaterLot> lots = Db.SP_getAllLots().ToList();
        return View(lots);
    }
}


View(Index):

@model IEnumerable<BASF.Models.SP_getAllLots_Result>
...
@Html.DisplayFor(modelItem => item.C2DBit)



Column-name of the table: "2DBIT"

When I debug the code and get an exception:当我调试代码并得到异常时:

System.Data.Entity.Core.EntityCommandExecutionException: 'The data reader is incompatible with the specified 'LotContext_NS.IS_MCC6CoaterLot'. A member of the type, 'C2DBit', does not have a corresponding column in the data reader with the same name.'

I think the problem ist, that the automatically generated code change the code of the mapped IS_MCC6CoaterLot.cs on the column with: C2DBIT.我认为问题在于,自动生成的代码将列上映射的 IS_MCC6CoaterLot.cs 的代码更改为:C2DBIT。 The Compiler don´t find the given column in the database und throw the error.编译器在数据库中找不到给定的列并抛出错误。 But what can i do to solve this problem?但我能做些什么来解决这个问题? is changing the column-name the only opportunity?更改列名是唯一的机会吗?

The problem you maybe running into is that your entities aren't updated to reflect changes to your database.您可能遇到的问题是您的实体没有更新以反映对数据库的更改。

The following is a pretty decent reference: https://www.entityframeworktutorial.net/efcore/working-with-stored-procedure-in-ef-core.aspx以下是一个相当不错的参考: https://www.entityframeworktutorial.net/efcore/working-with-stored-procedure-in-ef-core.aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从正在运行的 asp.net 网站上的 SQL 表中更改列名? - How can I change a column name from a SQL table on a running asp.net website? SQL Server:存储过程和ASP.NET - SQL Server : stored procedure and ASP.NET 如何存储将行或列值返回到ASP.NET C#变量的SQL存储过程结果? - How do I store a SQL stored procedure result that returns a row or a column value into an ASP.NET C# variable? 如何在 ASP.NET Core MVC 中使用 ADO.NET 将参数添加到存储过程? - How can I add parameters to a stored procedure using ADO.NET in ASP.NET Core MVC? 我可以使用带有实体框架(asp.net mvc)的另一台服务器上的一台服务器上的存储过程吗? - Can I use a stored procedure from one server on another with entity framework (asp.net mvc)? SQL Server 存储过程 - 无效的列名 - SQL Server stored procedure - invalid column name 如何在SQL Server中将列名和表名作为参数传递给存储过程? - How to pass column name as well as Table Name to a stored procedure as a parameter in SQL Server? 如何将SQL Server CE用于我的ASP.net MVC成员/授权项目? - How can I use SQL Server CE for my ASP.net MVC membership/authorization project? 如何在Linq-to-SQL和asp.net中使用存储过程? - How can I use a stored procedure in Linq-to-SQL and asp.net? 如何使用asp.net和命令参数将空值插入Sql Server日期列 - How can I insert a null value into Sql Server date column using asp.net and command parameters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM