Entity Framework 4.2: InsertFunction for Tables without PK
In Entity Framework 4.2, I am trying to insert a value into a table which has no PK. EF gives me the following error:
Unable to update the EntitySet 'ConditionTypesForWebApplications' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.
From the below discussion, I understood that it is possible to tweak that by editing the edmx file but it is not a best case when you are working with DbContext
class.
How do you update a table with a foreign key to another table in ADO.Net Entity Model?
Is there any better way of enabling this?
It is same for DbContext
with EDMX ( DbContext
without EDMX doesn't support entities without keys at all). Entity without key is read only unless you manually change EDMX file (be aware that any update model from database will delete your changes unless you buy more advanced tools for EDMX editing) or you will create stored procedure and map it to insert function of the entity.
In short entity should have key because EF should be able to uniquely identify it. Otherwise you can meet other problems in your application.
链接地址: http://www.djcxy.com/p/64924.html上一篇: 删除一个记录实体框架