I'm building a WCF service to retrieve a list of "AttributeName,AttributeGroup,AttributeValue"
For example,
AttributeName AttributeGroup AttributeValue
Document Type Information Systems User Guide
Document Type Information Systems Installation Instructions
Document Type Information Systems Policy
Document Type Finance Financial Statements
Application null ECM
Application null HR
Application null eData
Interest Survey 1 - Sign Me Up
Interest Survey 2 - Very Interested
Interest Survey 3 - Would Try
Interest Survey 4 - Would Watch
Interest Survey 5 - Not at all Interested
So far, so good. I want the WCF service to return a strongly-typed object:
[DataContract]
public class Categories
{
[DataMember]
public Dictionary<string, Category> CategoryList { get; set; }
public Categories ()
{
CategoryList = new Dictionary<string, Category>();
}
}
public class Category
{
public string CategoryName { get; set; }
public CategoryLookupValues LookupValues {get;set;}
public Category(string categoryName,CategoryLookupValues values)
{
CategoryName = categoryName;
LookupValues = values;
}
}
public class CategoryLookupValues
{
[DataMember]
public string AttributeName { get; set; }
[DataMember]
public Dictionary<string,string> AttributeValues { get; set; }
public CategoryLookupValues(string attributeName,ILookup<string,string> values)
{
AttributeName = attributeName;
AttributeValues = AttributeValues;
}
}
(don't nitpick just yet at my contract, still just trying to figure out how to populate the objects) :)
I'm using EF to get data from the database and I'm trying to use linq to populate the objects... I've got a few iterations. By the way the CategoryName attribute is passed in as a parameter and is not part of the results.
I was messing around with nested linq but I still just can't put my finger on it:
var lookup = (
from attributeGroup in model.ECMGeneralLookups
from attributeValue in model.ECMGeneralLookups
where attributeGroup.AttributeName.Equals("DocType")
select new{attributeGroup,attributeValue}
).ToLookup(x=>x.attributeValue,x=>x.attributeGroup);
(ECMGeneralLookups) is the table with the three columns at the start of the post.