2

I am getting this error in one of my development machine. This error is not happening in other machine which is pointing to same database. Definitely both servers are not identical. I don't know what software which is missing in one server cause this issue. Both machine is running same OS 2008 R2.

using (MYDB.MyDB oDB = new MYDB.MyDB())
        {
            var query = from t in oDB.Products
                        where (_ProductId.HasValue?_ProductId==t.Productid:true)
                        select new Product()
                       {
                           ProductId = t.Productid,
                           ManufacturerId = t.Manufacturerid,
                           ManufacturingNumber = t.Manufacturingnumber,
                           CustomProduct = t.Iscustomproduct ? "Yes" : "No",
                           IsCustomProduct = t.Iscustomproduct,
                           SubCategoryName = t.Subcategory.Subcategoryname
                       };
            return query.ToList();
        }

Any help is highly appreciated

Thanks, Senthilkumar

Esen
  • 973
  • 1
  • 21
  • 47

1 Answers1

1

I can not reproduce the exception in a comparable case, but the part _ProductId.HasValue?_ProductId==t.Productid:true looks suspect. I would change it as follows and if you're lucky it also solves your problem, otherwise it's an improvement anyway:

var query = from t in oDB.Products;
if (_productId.HasValue)
{
    query = query.Where(t => t.Productid == _productId.Value);
}
query = query.Select(t => new Product() {...

Another cause could be that Product.ProductId is not a nullable int.

musefan
  • 47,875
  • 21
  • 135
  • 185
Gert Arnold
  • 105,341
  • 31
  • 202
  • 291