我正在使用stored-procedure
更新表上的字段。我不想更新所有字段,因此不需要的字段未包含在存储过程中。
当我尝试使用以下代码从控制器调用stored-procedure
时,会得到:The
数据读取器与指定的“ EMSMVCModel.Call_Info”不兼容。类型为“ ambulanceDispatch”的成员在数据读取器中没有与之相同的对应列 名称。
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();
但是,我的表中还有更多字段,例如ambulanceDispatch
。我的call_info
类如下:
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 Server中,存储过程正在运行,如下所示。
请注意,我实际的存储过程还有更多字段。
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
答案 0 :(得分:2)
您的结果集(存储过程的输出)不包含名为
的列ambulanceDispatch
创建一个原始SQL查询,该查询将返回给定类型的元素。 该类型可以是具有与以下名称匹配的属性的任何类型 查询返回的列,或者可以是简单的原语 类型。该类型不必是实体类型。结果 即使对象类型,查询也不会被上下文跟踪 返回的是实体类型。使用SqlQuery(String,Object [])方法 返回由上下文跟踪的实体。
请注意,“ 类型可以是具有与查询返回的列名称相匹配的属性的任何类型,”
名称必须匹配。
您需要创建一个POCO对象,该对象与存储过程中返回列的(所有)列名和数据类型相匹配。
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