1

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")) };

EntityKey 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

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
brittongr
  • 329
  • 1
  • 11
  • "There are 54 key fields defined" check your model; it sounds like it thinks the entire table is the key, i.e. every field – Marc Gravell Jul 01 '11 at 10:35
  • I think it's doing that because is a database view not a table, but in the other hand i created the view WITH VIEW_METADATA. – brittongr Jul 01 '11 at 16:59

1 Answers1

1

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.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • That is a problem for me, because i have a database view per table added to the model and there is a lot of them. – brittongr Jul 01 '11 at 17:01