Ok so i made a really nasty mistake.
The problem wasn't with entity framework or connection.
The problem was with my LINQ query.
The correct query is
var query = from item in db.People
select item.Name;
题
I am trying to connect my C# application with SQL server compact edition using ADO.NET entity Model.
I think I have been successfully able to generate the model against the database schema.
However when I try to use the entity objects in code I get the
EntityCommandExecutionException` was unhandled error along with "An error occurred while executing the command definition. See the inner exception for details."
Here's the code
Database1Entities db = new Database1Entities();
var query = from item in db.People
select Name;
foreach (var item in query)
{
MessageBox.Show("The name of the customer is " + item);
}
It says to check inner exception. When I did checked InnerException gave me the error
"InnerException {"A parameter is not allowed in this location. Ensure that the '@' sign is in a valid location or that parameters are valid at all in this SQL statement."} System.Exception {System.Data.SqlServerCe.SqlCeException}"
Now I am entirely new to using entity framework for generating objects from database schemas. I would really appreciate some guidance in this regard.
解决方案
Ok so i made a really nasty mistake.
The problem wasn't with entity framework or connection.
The problem was with my LINQ query.
The correct query is
var query = from item in db.People
select item.Name;