Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

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.

share|improve this question

put on hold as off-topic by RobH, Brythan, Legato, Manny Meng, 200_success 2 days ago

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions containing broken code or asking for advice about code not yet written are off-topic, as the code is not ready for review. After the question has been edited to contain working code, we will consider reopening it." – RobH, Brythan, Legato, Manny Meng, 200_success
If this question can be reworded to fit the rules in the help center, please edit the question.

Browse other questions tagged or ask your own question.