2

I have a linq query in mvc4 application it gives me error

'Unable to create a constant value of type 'CMMIS.Domain.tblCustomer'. Only primitive types or enumeration types are supported in this context.'

. Any help is appreciable. Thanks in advance. Following is my code-

public List<tblEquipment> getEquipmentByLaneAndContractId(string Lane, string contractId)
{
        var query = (from c in _equipmentRepository.Table
                     from p in _customerRepository.Table
                     from q in _contractRepository.Table
                     where c.EquipLane == Lane && c.EquipActive == true && c.EquipCustID == p.CustID
                     && p.CustContractID == q.ContractID && q.ContractID == contractId
                     select c).ToList();

        return query;
}
Jens Kloster
  • 11,099
  • 5
  • 40
  • 54
Priyanka
  • 475
  • 6
  • 17
  • What is the type of `_equipmentRepository.Table` ? look at [this](http://stackoverflow.com/questions/7220867/unable-to-create-a-constant-value-of-type-type-only-primitive-types-such-as) – Jens Kloster May 06 '13 at 11:42

1 Answers1

0

I think something like this should work. This is assuming that the entity tables are linked to each other with foriegn key relationships.

public List<tblEquipment> getEquipmentByLaneAndContractId(string Lane, string contractId)
{
    var query =  (from c in _equipmentRepository.Table
                  where c.EquipLane == Lane &&
                        c.EquipActive == true &&
                        c.EquipCust.CustContractID == contractId
                  select c).ToList();

    return query;
}
SBurris
  • 7,378
  • 5
  • 28
  • 36