实体框架4 POCO与词典 [英] Entity Framework 4 POCO with Dictionary
问题描述
我有一个POCO(普通老CLR对象)
public Foo
{
public virtual int Id {get;组; }
public virtual Dictionary< string,string>东西{get;组; }
public virtual string更多{get;组; }
}
使用 model first 方法(即我还没有数据模型),我将如何处理持续的Stuff(Dictionary)? p>
这不是问题的真实答案,但由于没有其他答复,我会分享我所做的。 / p>
我只是创建了一个新的类型 {Id,Code,Text}
,并用该类型的列表替换了我的字典。然后我做这样的事情来获取密钥,值或者做一个查找:
列表< string>文本=(从s中的sv。可选值选择sv.Text).ToList();
列表< string>代码=(从s中的sv。可选值选择sv.Code).ToList();
string text =(from sv in q.SelectableValues where sv.Code ==MyKeyselect sv.Text).First();
在我的情况下,字典中的条目数量往往很小。但是,当字典/列表较大时,请参阅此问题以获取性能注意事项。
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)?
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.
这篇关于实体框架4 POCO与词典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!