I have added a function in Entity Framework and I am trying to understand why it wants to return an int
instead of a List<string>
.
I added the function to entity framework without an issue and once added and Validated the Context file looked as below:
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");
}
}
I am calling the function below :
public List<string> GetApplicationNames()
{
using (ComData.Entities db = new ComData.Entities())
{
return db.GET_ALL_APPS();
}
}
and here is the function that I added:
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;
Does anyone know why Entity Framework would look for an int
to come back instead of a List<string>
EDIT: The solution mentioned in the possible duplicate does not work because it involves T-SQL. This is PL/SQL and there is no equivalent to SET NOCOUNT ON
when used in a function.
I found the answer...
I ended up changing:
public List<string> GetApplicationNames()
{
using (ComData.Entities db = new ComData.Entities())
{
return db.GET_ALL_APPS();
}
}
to this:
public IQueryable<List<string>> GetApplicationNames()
{
using (ComData.Entities db = new ComData.Entities())
{
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<List<string>>("GET_ALL_APPS").ToList().AsQueryable();
}
}
Here is the link that I used to find the answer :
EDIT: While the above worked for me, I found a better way to solve the problem above this morning.
Double click the edmx file and Right Click the open space of the model designer and go into the model browser.
Right Click on the function that you are having a problem with and Click on Properties.
There is a option called Return Type to set what is being handed back...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.