Code: Select all
public class Contact
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public bool Checked { get; set; }
public string Mobile { get; set; }
public string Email { get; set; }
}
Code: Select all
CREATE OR REPLACE FUNCTION test_proc_pg()
RETURNS TABLE(id integer, name character varying, Checked boolean, Mobile character varying, Email character varying) AS
$BODY$
BEGIN
RETURN QUERY select temp1.id, temp1.Name, temp1.Checked, temp1.Mobile, temp1.Email from temp1;
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
Code: Select all
public static List<T> ExecuteProc<T>(string procname, params PgSqlParameter[] param)
{
List<T> list;
string paranames = string.Empty;
foreach (PgSqlParameter p in param)
{
if (paranames != string.Empty)
paranames += ", ";
paranames = paranames + "?";
}
using (var context = new EntityContext())
{
list = context.Database.SqlQuery<T>("select " + procname + "(" + paranames + ")", param).ToList<T>();
}
return list;
}
Code: Select all
public ActionResult ProcTest()
{
List<Contact> contacts = DAL.ExecuteProc<Contact>("test_proc_pg");
return View(contacts);
}
Code: Select all
{TestPG.Models.Contact}
Checked: false
Email: null
Id: 0
Mobile: null
Name: null
Code: Select all
public static List<T> ExecuteProc<T>(string procname, params SqlParameter[] param)
{
List<T> list;
string paranames = string.Empty;
foreach (SqlParameter p in param)
{
if (paranames != string.Empty)
paranames += ", ";
paranames = paranames + "@" + p.ParameterName;
}
using (var context = new SSContext())
{
list = context.Database.SqlQuery<T>("exec " + procname + " " + paranames, param).ToList<T>();
}
return list;
}
Code: Select all
public ActionResult ProcTest()
{
List<Contact> contacts = DAL.ExecuteProc<Contact>("test_proc_ss");
return View(contacts);
}
Code: Select all
{TestSS.Models.Contact}
Checked: false
Email: "[email protected]"
Id: 1
Mobile: "1234567890"
Name: "samtech"
I am using EF6 with latest trial version of dotConnect for PostgreSQL. I do not want to import functions.
I asked this question before at https://stackoverflow.com/questions/222 ... hout-impor but didn't receive any answer there.
Can someone help?