Or List<KeyValuePair<int,Object>>
, or a dictionary.
Depending on Entity Framework and PostgreSQL database we are trying to model a part of data which basically consists of a list of references to an object called OtherObject
which has an ID. The data we try to store is a MyObject
and consists of an Id
, and two lists (with a maximum length of 12) of one or more references to the OtherObject
and the amount of OtherObject
s. So we want to store data (in for example a separate table and columns) which correlates to this:
FirstPattern:
OtherObject with ID 1, 10 times
OtherObject with ID 4, 12 times
SecondPattern:
OtherObject with ID 2, 2 times
OtherObject with ID 3, 4 times
OtherObject with ID 4, 11 times
To do this we thought an ICollection
of KeyValuePair
s would be appropriate. That way we have a list that has a value (an amount) for each Key (the OtherObject
).
The model now basically looks as follows:
public class MyObject
{
public int Id { get; set; }
public IDictionary<OtherObject, int> FirstPattern { get; set; }
public IDictionary<OtherObject, int> SecondPattern { get; set; }
}
How can we possible store this ICollection
of KeyValuePair
s in the database?
Is there a (better) way?
string
value? OtherObject with ID 1, 10 times. Or is it actually broken down into columns that correlate to those results? – GregSO
check this posting as well it's pretty simplehttp://programmers.stackexchange.com/questions/185446/better-way-of-storing-key-value-pairs-in-the-database – MethodManhstore
in PostgreSQL. – Erwin Rooijakkers