元数据集合中不存在具有标识“'的成员。 [英] The member with identity '' does not exist in the metadata collection.

查看:382
本文介绍了元数据集合中不存在具有标识“'的成员。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Entity Framework 4通过自动生成的标识列向SQL Server 2008企业中的表添加行。标识列也是实体密钥。我尝试过这3种不同的方式:


ObjectContext.MyObjectSet.AddObject(myObject);
$
ObjectContext.AddToMyObjectSet(myObject);

ObjectContext.CreateObjectSet< MyObject>()。AddObject(myObject);


我在调用ObjectContext.SaveChanges()时得到这个:


"元素集合中不存在具有标识'的成员。

参数名称:identity"


当我对Linq-To-SQL做同样的事情时:


DataContext.MyObjectSet.InsertOnSubmit(myObject)

dataContext .SubmitChanges()


...它运行得很漂亮。


回到EF,如果我在SQL Server中禁用了标识列并手动分配了列在一个唯一值,它在实体框架中工作。


如何在SQL中启用标识自动生成列的实体框架中添加记录?


 

解决方案

您好mcroc,


您可以参考以下链接看到这种错误的一些解决方案。|

http://reykjavik.wordpress.com/2009/11/04/linq-to-entities-insert- problem-make-sure-the-qualifiedentitysetname-is-correct /

http://forums.oreilly.com/content/Programming-Entity-Framework/4676/Keep-Getting-Error/

http://social.msdn.microsoft.com/Forums/ en-US / adodotnetentityframework / thread / cef4f5f5-dad7-4064-988b-6e70fa1912bf /


祝你好运,

Alex Liang


I'm using Entity Framework 4 to add a row to a table in SQL Server 2008 enterprise with an auto generated identity column. The identity column is also the Entity Key. I've tried to do this 3 different ways:

ObjectContext.MyObjectSet.AddObject(myObject);
ObjectContext.AddToMyObjectSet(myObject);
ObjectContext.CreateObjectSet<MyObject>().AddObject(myObject);

I get this when calling ObjectContext.SaveChanges():

"The member with identity '' does not exist in the metadata collection.
Parameter name: identity"

When I do the same thing with Linq-To-SQL :

DataContext.MyObjectSet.InsertOnSubmit(myObject)
dataContext.SubmitChanges()

...it works beautifully.

Back to EF, if I disable the identity colum in SQL Server and manually assign the column to a unique value it does work in Entity Framework.

How do I add records in Entity Framework with the identiy auto-generated column enabled in SQL?

 

解决方案

Hi mcroc,

You can refer to the following links to see some solutions for this kind of error.|
http://reykjavik.wordpress.com/2009/11/04/linq-to-entities-insert-problem-make-sure-the-qualifiedentitysetname-is-correct/
http://forums.oreilly.com/content/Programming-Entity-Framework/4676/Keep-Getting-Error/
http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/cef4f5f5-dad7-4064-988b-6e70fa1912bf/

Best regards,
Alex Liang


这篇关于元数据集合中不存在具有标识“'的成员。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆