[英]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.