开发者

Entity Framework - GetObjectByKey don't allow the primary key

I'm trying to get a record using GetObjectByKey function like this:

Enumerable<KeyValuePair<string, object>> entityKeyValues =
                new KeyValuePair<string, object>[] { 
                new KeyValuePair<string, object>("JournalId", 
                                   new Guid("6491305f-91d9-4002-8c47-8ad1a870cb11")) };

En开发者_开发知识库tityKey key = new System.Data.EntityKey(string.Format("{0}.{1}", ObjectContextManager.Current.DefaultContainerName, "Journal"), entityKeyValues);

But i get this exception

System.ArgumentException: The provided list of key-value pairs contains an incorrect number of entries. There are 54 key fields defined on type 'Namespace.Journal', but 1 were provided. Parameter name: key

The type Journal is a view.

How can i do to use that function with just one field, the reason why i need that is because i don't want to specify a generic type , just one to get it from the given entity set name.

Thanks in advance


View in database doesn't have a key but EF needs it so when you insert the view to the model EF will take all non-nullable, non-binary columns and defines them as a key - at the moment your key consists of 54 columns. The solution is manually modifying EDMX file (as XML) but with default EDMX designer your changes will be deleted after each update from database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜