【发布时间】:2017-02-02 07:55:26
【问题描述】:
我正在开发一个 Windows 应用程序。我有一个从数据库生成的模型类型的实体模型。我首先导入了一些存储过程,对于一个 SP,我将上下文替换数据类型从 bool 更改为 int。现在,当我尝试更新模型(添加 SP)时,更改后的 SP 的上下文将返回其默认类型,即 bool 导致错误(函数具有无效参数)。
这是模型的 Context.cs。在这里,当我将类型从 bool 更改为 int 时,应用程序工作正常,但是当我更新模型时,类型又恢复为 bool 并抛出错误。如何避免这种情况?
public virtual ObjectResult<Web_get_obj_details_Result> Web_get_obj_details(Nullable<byte> hcode, Nullable<byte> vcode, Nullable<byte> yearcode, Nullable<short> tranno)
{
var hcodeParameter = hcode.HasValue ?
new ObjectParameter("hcode", hcode) :
new ObjectParameter("hcode", typeof(byte));
var vcodeParameter = vcode.HasValue ?
new ObjectParameter("vcode", vcode) :
new ObjectParameter("vcode", typeof(byte));
var yearcodeParameter = yearcode.HasValue ?
new ObjectParameter("yearcode", yearcode) :
new ObjectParameter("yearcode", typeof(byte));
var trannoParameter = tranno.HasValue ?
new ObjectParameter("tranno", tranno) :
new ObjectParameter("tranno", typeof(short));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<Web_get_obj_details_Result>("Web_get_obj_details", hcodeParameter, vcodeParameter, yearcodeParameter, trannoParameter);
}
我如何访问 SP:
IList<Web_get_obj_details_Result> ObjWeb_get_obj_details_Result = EntityObj.Web_get_obj_details(HobliCode, VillageCode, YearCode,TranNo).ToList<Web_get_obj_details_Result>();
这里 HobliCode、VillageCode、YearCode、TranNo 是 int 类型。
仅供参考:这是我的 SP
ALTER PROCEDURE [dbo].[Web_get_obj_details]
@hcode as tinyint , @vcode as tinyint , @yearcode as tinyint , @tranno as smallint
as
declare @dcode as integer , @tcode as integer
begin tran
select @dcode = dist_code , @tcode = taluk_code from mst_config
select convert(varchar(10),notice_sdate,103) as notice_sdate ,convert(varchar(10),obj_date,103) as obj_date,objector_name,obj_details from tr_objection
where dist_code= @dcode and taluk_code = @tcode and hobli_code = @hcode and village_code = @vcode and tran_no =@tranno and year_code=@yearcode
commit tran
我不想每次更新模型时都更改该 SP 的上下文。有什么解决办法??为什么即使类型是 int,模型也会将类型提取为 bool?
【问题讨论】:
-
您的意思是
bool或byte? -
@sefe 对不起.. 是字节..
标签: c# winforms entity-framework stored-procedures