1
我在實體框架中添加了一個函數,我試圖理解它爲什麼要返回int
而不是List<string>
。實體框架函數返回一個int而不是一個列表
我添加的功能實體框架沒有問題,一旦添加和驗證上下文文件看起來如下:
public partial class Entities : DbContext
{
public Entities()
: base("name=Entities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public DbSet<AppName> AppNames { get; set; }
public DbSet<AppStatus> AppStatus { get; set; }
public DbSet<Audit> Audits { get; set; }
public DbSet<EntryLog> EntryLogs { get; set; }
public DbSet<LogType> LogTypes { get; set; }
public DbSet<ModuleName> ModuleNames { get; set; }
public DbSet<Trace> Traces { get; set; }
public DbSet<Error> Errors { get; set; }
public virtual int GET_ALL_APPS()
{
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("GET_ALL_APPS");
}
}
我打電話以下功能:
public List<string> GetApplicationNames()
{
using (ComData.Entities db = new ComData.Entities())
{
return db.GET_ALL_APPS();
}
}
,這裏是我添加的功能:
create or replace FUNCTION GET_ALL_APPS RETURN SYS_REFCURSOR
AS
PO_RESULT SYS_REFCURSOR;
BEGIN
OPEN PO_RESULT FOR
SELECT UNIQUE
APP_NAME
FROM
LG_ENTRY_BASE_LOG;
RETURN PO_RESULT;
END;
有誰知道爲什麼實體框架會尋找int
而不是List<string>
編輯:在可能的重複中提到的解決方案不起作用,因爲它涉及T-SQL。這是PL/SQL,在函數中使用時沒有與SET NOCOUNT ON
等效。
我想這是因爲你宣佈它作爲'公共虛擬INT GET_ALL_APPS()' –
可能重複[存儲過程返回int,而不是結果集](http://stackoverflow.com/questions/18245567/stored-procedure-returns-int-instead-of-result-set) – cubrr
@SerhiyChupryk我相信這是由EF生成的。 – cubrr