Per MSDN documentation, there is no public constructor for the Lookup
class: http://msdn.microsoft.com/en-us/library/bb460184.aspx
You can create an instance of a Lookup<TKey, TElement>
by calling ToLookup
on an object that implements IEnumerable<T>
.
You will want to do something like:
new Component { ID = 1, Name = "MOBO", Category = new[] { … }.ToLookup(…) }
Update to address comments:
I'm not sure where you are getting your category info from, so I will make something up…
new Component {
ID = 1,
Name = "MOBO",
Category = new Dictionary<int, string> {
{ 3, "Beverages" }
{ 5, "Produce" }
}.ToLookup(o => o.Key, o => o.Value)
}
My guess is that your categories will come from some other source instead of instantiating a dictionary like I did here.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…