0

尝试在我的视图中过滤集合时,我收到一个奇怪的 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; }

}
4

1 回答 1

0

您的PricelistProduct类没有实现IEnumerableIQuerable接口,换句话说,它不是一个可以查询它的集合。
也许它应该Model.pricelistProduct.PricelistProductOptions在您的查询中,或者您的视图模型应该是一个集合?

连续作业也没有意义:

@{
//get corresponding PricelistProduct
PricelistProduct thisPP = new ProofPixLib.Models.PricelistProduct();
thisPP = ..;
}
于 2013-05-14T03:17:49.043 回答