KeyValuePair - without a constructor without parameters?

I have an object that has a property of type KeyValuePair.

I would like to read some data from the database and save the results in this field of type KeyValuePair.

myObject.KeyValuePairs = ctx.ExecuteQuery<KeyValuePair<String, int>>
                        ("Select " +
                            "[" + q.Name + "] As [Key]" +
                            ", Count([" + q.Name + "]) As [Value] From SomeTable" + 
                            " Group By [" + q.Name + "]").ToList(); 

myObject.KeyValuePairs is an List<KeyValuePair<String, int>>

When I try to read the entries, I get the following exception:

The type "System.Collections.Generic.KeyValuePair`2 [System.String, System.Int32]" must declare a default constructor (without parameters) so that it can be built during display.

I have a default constructor in the class, but this does not fix the problem. It seems like he does not know how to create a KeyValuePair object. Does it have a default constructor? Confused ..

thank

+5
source share
1 answer

, KeyValuePair<TKey, TValue> - , .

, EF , struct.

EF , ( ).

, , KeyValuePair<TKey, TValue> , Key Value .

,

class NameCount {
    public string Name { get; set; }
    public int Count { get; set; }
}

, Key Name Value Count. , .

+14

All Articles