【发布时间】:2015-11-11 07:22:39
【问题描述】:
【问题讨论】:
-
我看不到屏幕截图,但您通常在设置参数值时使用
DBNull.Value而不是null。 -
解决了,谢谢。我创建了一个对象,如果它为空,则将该对象设置为 DbNull.Value,否则将其设置为属性值。
标签: c# entity-framework
【问题讨论】:
DBNull.Value 而不是null。
标签: c# entity-framework
D Stanley 在 cmets 中有正确答案。
你不能将null传递给SqlParameter,你需要传递DbNull.Value。
所以:
object comments = detail.ReferralComments;
if (comments == null) {
comments = DBNull.Value;
} else {
comments = detail.ReferralComments;
}
db.Database.ExecuteSqlCommand("EXEC dbo.Dual_SaveReferral @quoteGuid, @referralTypeID, @comments",
new SqlParameter("@quoteGuid", detail.QuoteGuid),
new SqlParameter("@referralTypeID", detail.ReferralTypeID),
new SqlParameter("@comments", comments));
}
【讨论】: