数据 reader 与指定的模型不兼容

Data reader is incompatible with the specified model

我正在使用 stored-procedure 更新 table 上的字段。我不想更新所有字段,因此不需要的字段未包含在存储过程中。

当我尝试使用以下代码从控制器调用 stored-procedure 时,我得到:The

data reader is incompatible with the specified'EMSMVCModel.Call_Info'. A member of the type, 'ambulanceDispatch',does not have a corresponding column in the data reader with the same name.

 var insert_query = entities.Database.SqlQuery<Call_Info>("exec [dbo].[update_call_info]  @call_info_id, @call_id, @user_id, @ambulanceNum, @patientId, @patientName, @dateOfBirth, @ethnicity, @gender,
                        new SqlParameter("call_info_id", call_info_id),
                        new SqlParameter("call_id", call_id),
                        new SqlParameter("user_id", u_id),
                        new SqlParameter("ambulanceNum", ambulanceNum),
                        new SqlParameter("patientId", patientId),
                        new SqlParameter("patientName", patientName),
                        new SqlParameter("dateOfBirth", dateOfBirth),
                        new SqlParameter("ethnicity", ethnicity),
                        new SqlParameter("gender", gender)
                        )
                        .Select(x => new
                        {
                            x.call_info_id,
                            x.call_id,etUser,
                            x.Call,*/
                            StatusCode = 1 //Success StatusCode
                        }).ToList();

但是,我的 table 有更多字段,例如 ambulanceDispatch。我的 call_info class 如下:

 public partial class Call_Info
    {
        public int call_info_id { get; set; }
        public int call_id { get; set; }
        public string user_id { get; set; }
        public int ambulanceNum { get; set; }
        public string patientId { get; set; }
        public string patientName { get; set; }
        public System.DateTime dateOfBirth { get; set; }
        public string ethnicity { get; set; }
        public Nullable<int> gender { get; set; }
        public System.DateTime ambulanceDispatch { get; set; }
        public System.DateTime arrivalOnScene { get; set; }

    }

在 SQL 服务器中,存储过程正在运行,如下所示。

注意我的实际存储过程有更多字段。

call_info_id    call_id user_id ambulanceNum    patientId   patientName dateOfBirth ethnicity   gender  address_line    post_code_num   allergies   categories  history crash   historyTextOther    crashTextOther  symptoms    skin    monitoring  section1    section2    section3    section4    section5    section6    section7    section8    section9    section10   section11   section12   section13   section14   section15   section16   section17   section18   section19   section20   section21   section22   section23   section24   section25   section26   section27   section28   section29   section30   section31   section32   section33   section34   section35   section36   section37   section38   section39   section40   section41   section42   section43   section44   section45   section46   section47   section48   section49   section50   section51   section52   AP  breaths oxygen  temp    pulse   left    right   resistance  speech  limb    mouth   chemicals   explosives  gases   flammable   radioactive indications interventions   types   doses   diodes  transport   medicineType    medicineDosage  medicinePlace
2   91390   e67db6bc-3866-446e-a2dd-e5504190ac12    42  1   Andreas Georgiou    2000-04-03 00:00:00.000 Cypriot 3   1, Test Street  1234    0   0   0   0   N/A N/A 0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   N/A N/A N/A N/A N/A N/A N/A N/A 0   0   0   0   0   0   0   0   0   0   0   0   0   0   N/A N/A changeit

您的结果集(存储过程的输出)不包含名为

的列

救护车调度

https://docs.microsoft.com/en-us/dotnet/api/system.data.entity.database.sqlquery?view=entity-framework-6.2.0

Creates a raw SQL query that will return elements of the given type. The type can be any type that has properties that match the names of the columns returned from the query, or can be a simple primitive type. The type does not have to be an entity type. The results of this query are never tracked by the context even if the type of object returned is an entity type. Use the SqlQuery(String, Object[]) method to return entities that are tracked by the context.

请注意“类型可以是具有与查询中 return 列名称相匹配的属性的任何类型,

名称必须匹配。

您需要创建一个 POCO 对象来匹配存储过程中 return 列的(所有)列名和数据类型。

call_info_id
call_id
user_id
ambulanceNum
patientId
patientName
dateOfBirth
ethnicity
gender
address_line
post_code_num
allergies
categories
history
crash
historyTextOther
crashTextOther
symptoms
skin
monitoring
section1
section2
section3
section4
section5
section6
section7
section8
section9
section10
section11
section12
section13
section14
section15
section16
section17
section18
section19
section20
section21
section22
section23
section24
section25
section26
section27
section28
section29
section30
section31
section32
section33
section34
section35
section36
section37
section38
section39
section40
section41
section42
section43
section44
section45
section46
section47
section48
section49
section50
section51
section52
AP
breaths
oxygen
temp
pulse
left
right
resistance
speech
limb
mouth
chemicals
explosives
gases
flammable
radioactive
indications
interventions
types
doses
diodes
transport
medicineType
medicineDosage
medicinePlace