3

I have the following 3 classes.

A workflow configuration has one brand and one workflowtype.

I need one method in linq or EF that gets me all the brands of existing workflowconfiguration and another method that gets me all the brands of non existing workflow configuration.

I am lost cause I dont know where to start.

public class Brand
    {
        public int BrandId { get; set; }
        public string Name { get; set; }
    }


  public class WorkflowType
    {
        public int WorkflowTypeId { get; set; }
        public string Name { get; set; }
    }

 public class WorkflowConfiguration
    {
        public int WorkflowConfigurationId { get; set; }
        public WorkflowType WorkflowType { get; set; }
        public Brand Brand { get; set; }
        public virtual ICollection<Approver> Approvers { get; set; }

    }

Update1 Here are how my tables would look like and the expected result

Brand

  1. Audi

  2. Volkswagen

  3. Mercedes

WorkflowTYpes

  1. type 1

  2. type 2

  3. type 3

WorkflowConfiguration

brandid, workflowtype id

1 ------------ 1

1 -------------2

List<string> GetBrandsForExistingWorkflowType(string worfklowtype)

If I pass type1 to this method it should return: Audi because for type1, audi exists on the table

List<string> GetBrandsForNonExistingWorkflowType(string workflowType)

If I pass type1 to this method it should return. Volkswagen and Mercedes because for type1, those 2 brands are not in the relationship.

Luis Valencia
  • 32,619
  • 93
  • 286
  • 506
  • What does an existing workflowconfiguration and a non existing workflowconfiguration mean.? – Muthukumar May 29 '12 at 07:22
  • Post your effort. To get start see http://weblogs.asp.net/bradvincent/archive/2008/11/01/linq-cheat-sheet.aspx – Tassadaque May 29 '12 at 07:22
  • Start by defining what your expected result will look like - then think about what data you need to join on which fields. Try something simple first, like getting Workflow configuration id for a brand id. This way if you run into problems you'll be able to come back to us and tell us what exactly it is that you don't know how to achieve. – Joanna Derks May 29 '12 at 07:24
  • I have updated my question to show what I need and my methods signature – Luis Valencia May 29 '12 at 07:30

1 Answers1

4

I think this is what you want:

List<string> GetBrandsForExistingWorkflowType(string worfklowtype)
{
    var result = db.WorkflowConfigurations
                 .Where(x => x.WorkflowType.Name == worfklowtype)
                 .Select(x => x.Brand);
    return result;
}

List<string> GetBrandsForNonExistingWorkflowType(string workflowType)
{
    var excluded = GetBrandsForExistingWorkflowType(string worfklowtype);
    var result = db.Brands.Except(excluded);
    return result;
}
david.s
  • 11,283
  • 6
  • 50
  • 82