I am in the process of building a WCF service using EF to a Microsoft SQL Server but keep getting the following error:
Additional information: No mapping exists from object type System.Data.Objects.ObjectParameter to a known managed provider native type.
On this query:
string ID = "XXID"; string Sql = @"SELECT * FROM @Table WHERE " + ID + " LIKE '@SearchTerm'"; ObjectParameter[] Parameters = new ObjectParameter[2]; Parameters[0] = new ObjectParameter("Table", Table); Parameters[1] = new ObjectParameter("SearchTerm", SearchTerm); using (var Context = new XXEntities()) { Context.Database.Connection.Open(); IEnumerable<string> Query = Context.Database.SqlQuery<string>(Sql, Parameters); string[] Results = Query.ToArray(); Context.Database.Connection.Close(); return Results; }
I have tested the query on SQL Server and it works as expected- returning the record of a matched ID.