解决LINQ错误:缺少查询模式实现

时间:2013-05-13 23:41:21

标签: linq asp.net-mvc-4

在我的视图中尝试过滤集合时,我收到一个奇怪的LINQ错误。

这是我的模特:

public class adminEditProductsPricelistProductsVM
{
    public Product Product { get; set; }
    public PricelistProduct pricelistProduct { get; set; }
}

这是我的观点:

@using Pp.Lib.Models;
@using System.Linq;
@model PpLib.viewModels.admin.adminEditProductsPricelistProductsVM

@{
//get corresponding PricelistProduct
PricelistProduct thisPP = new ProofPixLib.Models.PricelistProduct();
thisPP = (from x in Model.pricelistProduct where x.ProductId == Model.Product.ProductId      select x).FirstOrDefault();   
}

Model.pricelistProduct 行在VS中加下划线,并显示以下错误:

  

找不到源类型Pp.Lib.Models.PricelistProduct的查询模式的实现。 '哪里'找不到。

提前感谢您的帮助!

更新 根据要求 - 这是PricelistProduct模型的代码。

public partial class PricelistProduct
{
    public PricelistProduct()
    {
        this.PricelistProductOptions = new List<PricelistProductOption>();
    }

    [ReadOnly(true)]
    [Display(Name = "Pricelist Product ID")]
    public int PricelistProductId { get; set; }

    [ReadOnly(true)]
    [Display(Name = "Pricelist ID")]
    public int PricelistId { get; set; } //foregin key
    public virtual Pricelist Pricelist { get; set; }

    [ReadOnly(true)]
    [Display(Name = "Product ID")]
    public int ProductId { get; set; } //foreign key
    public virtual Product Product { get; set; }

    [HiddenInput]
    public int ProductCategoryId { get; set; } // not a FK but data only
    public virtual ProductCategory ProductCategory { get; set; }

    [Display(Name = "Use formula")]
    private bool _UsesFormula = true;
    public bool UsesFormula { get { return _UsesFormula; } set { _UsesFormula = value; } }

    private decimal _Price = 0;
    public decimal Price  { get { return _Price; } set { _Price = value; } }

    [Display(Name = "Use discount pricing")]
    private bool _HasDiscountPricing = false;
    public bool HasDiscountPricing { get { return _HasDiscountPricing; } set { _HasDiscountPricing = value; } }

    [Display(Name = "Local shipping price")]
    private decimal _LocalShipPrice = 0;
    public decimal LocalShipPrice { get { return _LocalShipPrice; } set { _LocalShipPrice = value; } }

    [Display(Name = "Intl. shipping price")]
    private decimal _IntlShipPrice = 0;
    public decimal IntlShipPrice { get { return _IntlShipPrice; } set { _IntlShipPrice = value; } }

    [Display(Name = "Item is taxable")]
    private bool _isTaxable = true;
    public bool isTaxable { get { return _isTaxable; } set { _isTaxable = value; } }

    public virtual List<PricelistProductOption> PricelistProductOptions { get; set; }

}

1 个答案:

答案 0 :(得分:0)

您的PricelistProduct课程没有实现IEnumerableIQuerable个界面,换句话说,它不是要通过它查询的集合。
也许在您的查询中应该是Model.pricelistProduct.PricelistProductOptions,或者您的视图模型应该是一个集合?

连续作业也没有意义:

@{
//get corresponding PricelistProduct
PricelistProduct thisPP = new ProofPixLib.Models.PricelistProduct();
thisPP = ..;
}