存储过程的实体框架映射错误

本文关键字:映射 错误 框架 实体 存储过程 | 更新日期: 2023-09-27 18:25:32

我正在用C#代码调用SP。Everythig一直在工作,直到我想更改SP的结果类型。

比如从Int32到String的一些值,以及从Double到Decimal的一些值。

现在,我在调用或调用sp的映射时遇到了这个错误。

German:
Die Eigenschaft 'VBENr' bei 'Report_Result' konnte nicht auf einen 'Int32'-Wert festgelegt werden. Sie müssen diese Eigenschaft auf einen Nicht-NULL-Wert des Typs 'String' festlegen.
English:
The Property 'VBENr' in 'Report_Result' could not be set to a 'Int32' value. You must set this property to a non-null value of type 'String'.

我不能做这个改变,因为它已经是设计师的样子了。我读到一些关于设计器工作不正常的内容,所以我也在designer.cs和*.edmx 中更改了值

例如,VBENr值:

Edmx:

      <Property Type="String" Name="VBENr" Nullable="false" />

Deisgner.cs:

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String VBENr
        {
            get
            {
                return _VBENr;
            }
            set
            {
                OnVBENrChanging(value);
                ReportPropertyChanging("VBENr");
                _VBENr = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("VBENr");
                OnVBENrChanged();
            }
        }
        private global::System.String _VBENr;
        partial void OnVBENrChanging(global::System.String value);
        partial void OnVBENrChanged();

真的不知道我为什么会收到这个错误消息。。

谢谢

Markus

存储过程的实体框架映射错误

有时代码生成器不会接受/刷新您的更改。当这种情况发生在我身上时,我会遵循以下步骤:

  1. 从edmx中删除表
  2. 保存.edmx
  3. 添加表(从数据库更新模型)
  4. 保存.edmx
  5. 自己运行t4脚本(右键单击.tt文件,点击Run Custom Tool)

不要编辑生成的代码,因为下次修改和保存.edmx时,所做的更改将丢失。