![](/img/trans.png)
[英]How to import existing stored procedure in Entity Framework code-first from entity data wizard?
[英]How to use existing stored procedure & functions with Entity Framework Code-first
我正在使用EntityFramework.Functions
庫,當我們首先使用實體框架代碼時,該庫用於調用存儲過程或函數。
我有一個存儲過程,它返回一個可為空的 long 值。 但我收到一個錯誤:
System.Nullable`1[[System.Int64, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] 在概念模型中作為結構類型不支持 AddRecord_SP 方法。
這些函數在我的DataContext
類中聲明:
[Function(FunctionType.StoredProcedure, "Sp_name", Schema = "acnt")]
public virtual ObjectResult<Nullable<long>> AddRecord_SP(string i_Params)
{
var i_ParamsParameter = i_Params != null ?
new ObjectParameter("I_Params", i_Params) :
new ObjectParameter("I_Params", typeof(string));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<Nullable<long>>("Sp_name", i_ParamsParameter);
}
據我所知,存儲過程實際上不能指定參數不可為空。
可能你可以嘗試指定返回參數。
[return: Parameter(DbType = "")]
以下是我的項目中的示例代碼,您可以參考。
[Function(FunctionType.StoredProcedure, "GetTop100", Schema = "biz")]
public IQueryable<GetTop100Emp> GetTop100EmpList(long? FKTenant, int IsFilter)
{
var parameters = new ObjectParameter[] {
new ObjectParameter("FKTenant", FKTenant),
new ObjectParameter("IsFilter", IsFilter),
};
return this.ObjectContext.ExecuteFunction<GetTop100Emp>("GetTop100", parameters).AsQueryable<GetTop100Emp>();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.