Silly thing this.
Found this link.
In my case this was caused by not selecting the primary key for the table in SQL Server I was generating the entity set against and then attempting to call the Entity Framework AddObject method with the generated entity. I’m pretty sure that this sort of error will occur though with just about any operation you try against the DB with the entity if you haven’t defined a primary key.
Found this with ASP.Net MVC 2. New table, no PK; when connected to with ADO.Net Data Entity model, the .edmx file created by Visual Studio sets up a block in the xml. Having removed that version of the edmx and defining a PK on the table, reconnecting with a new Data Entity model (could probably achieve same by selecting ‘Update Model from Database’) sees no DefiningQuery block in the xml.
In fact I would very much recommend the ‘Updating the Model from Database’ option as to remove and re-add the edmx is quite painful; the original connection had deep hooks into a lot of things and just removing the edmx broke all subsequent attempts to reconnect until all the hooks had been removed.
Crap error message in a crap system. If you do get this DefiningQuery error message check the ‘Messages’ portion of the error list on Visual Studio: you may well have a “no primary key has been defined and has had to be inferred” message, although if you are using a view this may not be applicable.