I'm using EF 6.1.1 and trying the SqlQuery method to build dynamic queries.
This code:
using (DBAuraContext context = new DBAuraContext(EFConnectionString))
{
string sql = "SELECT * FROM Assortimenti WHERE CodiceAssortimento > {0}";
System.Data.Entity.Infrastructure.DbRawSqlQuery<Assortimenti> rawRows =
context.Database.SqlQuery<Assortimenti>(sql, "A");
List<Assortimenti> assortim = rawRows.ToList<Assortimenti>();
foreach(Assortimenti ass in assortim)
{
Console.WriteLine(ass.CodiceAssortimento);
}
}
throws a PgSqlException with message {"la colonna \"p0\" non esiste"} (column p0 doesn't exist).
What is wrong in this code ?
Entity Framework and SqlQuery
Re: Entity Framework and SqlQuery
Please use
or
instead of
For more information, refer to http://www.devart.com/dotconnect/postgr ... eters.html.
Code: Select all
string sql = "SELECT * FROM Assortimenti WHERE CodiceAssortimento > ?";
Code: Select all
string sql = "SELECT * FROM Assortimenti WHERE CodiceAssortimento > $1";
Code: Select all
string sql = "SELECT * FROM Assortimenti WHERE CodiceAssortimento > {0}";
-
- Posts: 7
- Joined: Fri 19 Dec 2014 07:42
Re: Entity Framework and SqlQuery
Ok, I tried your suggestion and it works.
I was using the syntax {0} because with Sql Server Provider it seems it's the only supported, and i supposed that parameters syntax was the same.
Thank you for your reply
I was using the syntax {0} because with Sql Server Provider it seems it's the only supported, and i supposed that parameters syntax was the same.
Thank you for your reply