0

I have a Real Estate site with a Properties table and a PropertyImages table. When the user uploads a picture, I want to run a query in the PropertyImages. then append that number to the picturename.

    public IQueryable GetPictureCount()
   {
     int propertyId = Convert.ToInt16(ddlSelectProperty.SelectedValue);
     var _db = new RESolution.Models.PropertyContext();
     IQueryable query = _db.PropertyImages;

    var mypic = (from c in _db.PropertyImages
                where c.PropertyID == propertyId
                select c).FirstOrDefault();
            lblCount.Text = Convert.ToString(query);
    }

I get this error: "Not all code paths return a value"

My environment is as follows:

VS Express 2013
Sql Express 
win 8.1 development computer

when I change IQuaryable to "void" I get the error

'lblCount.text = query.Count().ToString();' System.Linq.IQueryable does not contain a definition for 'Count' I have looked for a using directive but found non

2
  • You have to invoke the query and print the result: lblCount.text = query.Count().ToString(); Commented Nov 17, 2014 at 15:43
  • 3
    Since your method is called GetPictureCount, and because it is declared as returning IQueryable, there needs to be a return statement somewhere. If you use your method for its side effects, replace IQueryable with void to fix the error. Commented Nov 17, 2014 at 15:47

2 Answers 2

1

I am still a little confused, though you guys are a god send. Here is where I was able to get to work.

public void GetPictureCount() {

        lblfnameCheck.Text = ddlSelectProperty.SelectedValue;
        int propertyId = Convert.ToInt32(lblfnameCheck.Text);
        var _db = new RESolution.Models.PropertyContext();

        var count = _db.PropertyImages.Count(t => t.PropertyID == propertyId);
        lblCount.Text = Convert.ToString(count);

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

Comments

0

As dasblinkenlight mentioned, it seems that you do not want to return something, so make the method a void. You probable want something like this:

public void GetPictureCount()
{
   int propertyId = Convert.ToInt16(ddlSelectProperty.SelectedValue);
   var _db = new RESolution.Models.PropertyContext();
   IQueryable query = _db.PropertyImages;

   var mypic = (from c in _db.PropertyImages
            where c.PropertyID == propertyId
            select c).FirstOrDefault();

   var nrOfPics = Convert.ToString(query.Count());
   lblCount.Text = nrOfPics;
   mypic.name = mypic.name + nrOfPics; // I am guessing the name property

  _db.SaveChanges();
}

1 Comment

var nrOfPics = Convert.ToString(query.Count()); shows an error that IQueryable does not contain a definition 'Count' also the following has runtime error int propertyId = Convert.ToInt16(ddlSelectProperty.SelectedValue);

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.