【问题标题】:Unable to create a constant value of type 'ABC'. Only primitive types or enumeration types are supported in this context无法创建类型为“ABC”的常量值。此上下文仅支持原始类型或枚举类型
【发布时间】:2013-04-30 03:32:14
【问题描述】:

我在 mvc4 应用程序中有一个 linq 查询,它给了我错误

'无法创建'CMMIS.Domain.tblCustomer'类型的常量值。 仅支持原始类型或枚举类型 上下文。'

。任何帮助都是可观的。提前致谢。以下是我的代码-

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;
}

【问题讨论】:

  • _equipmentRepository.Table 的类型是什么?看this

标签: asp.net-mvc c#-4.0 asp.net-mvc-4 linq-to-entities entity-framework-4.1


【解决方案1】:

我认为这样的事情应该可行。这是假设实体表通过外键关系相互链接。

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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-26
    • 1970-01-01
    • 2020-10-08
    • 2015-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多