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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.