0

I wrote services class.

 public partial class ProductService : IProductService
    {
        #region Constants

        private const string PRODUCTVARIANTPRICERANGE_PATTERN_KEY = "Nop.productVariantPriceRange.";
        #endregion

        #region Fields


        private readonly IRepository<ProductVariantPriceRange> _productVariantPriceRangeRepository;

        public ProductService(ICacheManager cacheManager,

            IRepository<ProductVariantPriceRange> productVariantPriceRangeRepository,
            )
        {

            this._productVariantPriceRangeRepository = productVariantPriceRangeRepository;

        }

        #endregion

Then write a function

 public virtual void CheckProductVariantPriceRange(int productVariantPriceRangeId)
        {
            bool flage=true;
            var query = _productVariantPriceRangeRepository.Table;

               query = query.Where(m => m.ProductVariantId.Contains(productVariantPriceRangeId));


            var ProductVariantPriceRangeS = query.ToList();
            if (ProductVariantPriceRangeS.Count == 0)
            {
                flage = false;
            }

        }

but It occur the flowing error..

  1. Instance argument: cannot convert from 'int' to 'System.Linq.IQueryable<int>'

  2. 'int' does not contain a definition for 'Contains' and the best extension method overload 'System.Linq.Queryable.Contains(System.Linq.IQueryable, TSource)' has some invalid arguments

I don't know what is this error. How can I solve this.. Plz help

aruni
  • 2,664
  • 10
  • 44
  • 68
  • 1
    What is this line supposed to do? : `query = query.Where(m => m.ProductVariantId.Contains(productVariantPriceRangeId));` – wasyl Sep 19 '12 at 06:45

2 Answers2

1

The ProductVariantId property is not a collection, it's a single value. You should compare the value in the property for each record to the desired value:

query = query.Where(m => m.ProductVariantId == productVariantPriceRangeId);
Guffa
  • 687,336
  • 108
  • 737
  • 1,005
1

Remove the Contains method call. In other words, replace:

query = query.Where(m => 
    m.ProductVariantId.Contains(productVariantPriceRangeId));

with

query = query.Where(m => m.ProductVariantId == productVariantPriceRangeId);
akton
  • 14,148
  • 3
  • 43
  • 47