Page 1 of 1

Problem With CreateQuery<>

Posted: Fri 16 Jul 2010 16:43
by daveoggy
I don't seem to be able to use QueryCreate. I have the following code:

Code: Select all

                using (Entities ent = new Entities())
                {
                    String sql = string.Format(@"SELECT * FROM tm_fnet");

                    var results = ent.CreateQuery(sql);

                    foreach (var row in results)
                    {
                        RTTrace.WriteLine(this.TraceName, "id " + row.ID.ToString());
                    }
                }
This results in the error:

"The query syntax is not valid., near term '*', line 1, column 11."

This one is driving me crazy!

Posted: Wed 21 Jul 2010 11:27
by AndreyR
The CreateQuery method takes Entity SQL query, not SQL query.
Take a look at the Entity SQL article in MSDN for details.
To execute the SQL query you can use the ObjectContext.ExecuteStoreQuery method.
Please note that it is available in Entity Framework v4 only.