Call Function from Postgres Database in Visual Studio from Devart Entity Model
Posted: Tue 26 Jul 2016 12:25
Hello,
I am using Devart Entity Model in my web API/MVC application with Postgres Database.
I have function in Database with the name "fn_getalltaxreturns" whose return type is table(projid int, taxid, intger,name character).
I use Entity Framework with Database-first approach, so my edml file I have imported this function.
I define above function in my class "EdmFunction" as
[EdmFunction("Dd8degrlj74h2fModel.Store", "fn_getalltaxreturns")]
public IEnumerable<taxtype> fn_getalltaxreturns()
{
Dd8degrlj74h2fEntities context = new Dd8degrlj74h2fEntities();
IEnumerable <taxtype> t = context.
CreateQuery<taxtype>("Dd8degrlj74h2fModel.Store.fn_getalltaxreturns()")
.Execute(MergeOption.NoTracking)
.ToList();
return t;
}
And in web api controller I call above function as
edmfunctions cls = new edmfunctions();
IEnumerable<taxtype> taxtype=cls.fn_getalltaxreturns();
Here it throws error
{"The specified cast from a materialized 'System.String' type to the 'TestWebAPI.Models.taxtype' type is not valid."}
How do I call postgres functions returning list of records in Devart Entity Model.
Thanks in Advance.
I am using Devart Entity Model in my web API/MVC application with Postgres Database.
I have function in Database with the name "fn_getalltaxreturns" whose return type is table(projid int, taxid, intger,name character).
I use Entity Framework with Database-first approach, so my edml file I have imported this function.
I define above function in my class "EdmFunction" as
[EdmFunction("Dd8degrlj74h2fModel.Store", "fn_getalltaxreturns")]
public IEnumerable<taxtype> fn_getalltaxreturns()
{
Dd8degrlj74h2fEntities context = new Dd8degrlj74h2fEntities();
IEnumerable <taxtype> t = context.
CreateQuery<taxtype>("Dd8degrlj74h2fModel.Store.fn_getalltaxreturns()")
.Execute(MergeOption.NoTracking)
.ToList();
return t;
}
And in web api controller I call above function as
edmfunctions cls = new edmfunctions();
IEnumerable<taxtype> taxtype=cls.fn_getalltaxreturns();
Here it throws error
{"The specified cast from a materialized 'System.String' type to the 'TestWebAPI.Models.taxtype' type is not valid."}
How do I call postgres functions returning list of records in Devart Entity Model.
Thanks in Advance.