2013-05-13 32 views
0

我在嘗試過濾視圖中的集合時收到一個奇怪的LINQ錯誤。解決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和它說了以下錯誤:

Could not find an implementation of the query pattern for source type Pp.Lib.Models.PricelistProduct. 'Where' not found.

在此先感謝您的幫助!

UPDATE 按要求 - 這裏是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; } 

} 
+0

是否也可以說你缺少「System.Core.dll」引用或using指令「System.Linq的」?如果是這樣,你應該包括使用System.Linq。 – 2013-05-13 23:46:17

+0

謝謝,但我有@using System.Linq;在我看來的頂部。 – 2013-05-13 23:57:21

+1

您可以發佈PricelistProduct的代碼嗎?它是否實現IEnumerable? – kgu87 2013-05-14 00:33:55

回答

0

PricelistProduct類不能實現IEnumerableIQuerable接口,換句話說,它是不是在查詢它的集合。
也許它應該是Model.pricelistProduct.PricelistProductOptions在您的查詢或您的視圖模型應該是一個集合?

連續分配沒有意義,以及:

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

謝謝!你是對的 - 沒有必要列舉這個 - 調用這個部分的父母已經這樣做了。我感到愚蠢! – 2013-05-14 12:50:05