实体框架函数返回int而不是List

时间:2015-10-20 19:02:08

标签: c# entity-framework oracle11g

我在Entity Framework中添加了一个函数,我试图理解它为什么要返回int而不是List<string>

我在没有问题的情况下将该函数添加到实体框架中,并且一旦添加并验证了Context文件,如下所示:

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

1 个答案:

答案 0 :(得分:0)

我找到了答案......

我最后改变了:

public List<string> GetApplicationNames()
{
    using (ComData.Entities db = new ComData.Entities())
    {
        return db.GET_ALL_APPS();                 
    }
}

到此:

public IQueryable<List<string>> GetApplicationNames()
    {
        using (ComData.Entities db = new ComData.Entities())
        {

            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<List<string>>("GET_ALL_APPS").ToList().AsQueryable();

        }
    }

以下是我用来查找answer的链接:

编辑:虽然上述内容对我有用,但我今天上午找到了解决问题的更好方法。

双击edmx文件并右键单击模型设计器的开放空间,然后进入模型浏览器。

右键单击您遇到问题的功能,然后单击“属性”。

有一个名为Return Type的选项可以设置正在传回的内容......

相关问题