views:

160

answers:

1

I have a POCO (Plain Old CLR Object)

public Foo
{
   public virtual int Id { get; set; }
   public virtual Dictionary<string, string> Stuff { get; set; }
   public virtual string More { get; set; }
}

Using the model first approach (i.e. I don't have a data model yet), how would I handle persisting Stuff (Dictionary)?

+1  A: 

This is not a true answer to the question, but since there are no other replies, I'll share what I did.

I simply created a new type {Id, Code, Text} and replaced my dictionary with a list of that type. I then do something like this to get the keys, values, or do a lookup:

List<string> texts = (from sv in q.SelectableValues select sv.Text).ToList();
List<string> codes = (from sv in q.SelectableValues select sv.Code).ToList();
string text = (from sv in q.SelectableValues where sv.Code == "MyKey" select sv.Text).First();

In my case the number of entries in the dictionary tends to be small. However, see this question for performance considerations when the dictionary/list is large.

Eric J.