0

How can I view Sklep data with specified id.

I can see id's of Sklep and Miejsce from Sklep_has_Miejsce with specified number id of Miejsce, but cant view items from Sklep table with id from parameter.

I got

Cannot implicitly convert type 'Sklepy.Models.DB.Sklep' to 'System.Collections.Generic.IEnumerable'. An explicit conversion exists (are you missing a cast?) error.

 public ActionResult Index(int? id)
{
    var viewModel = new ProduktIndexData();
    viewModel.Miejsces = db.Miejsces
        .Include(i => i.Sklep_has_Miejsce.Select(s => s.Sklep))
        .OrderBy(i => i.Nazwa);

   if (id !=null)
    {
        ViewBag.MiejsceIDa = id.Value;
        viewModel.Sklep_has_Miejsces = viewModel.Miejsces.Where(i => i.MiejsceID == id.Value).Single().Sklep_has_Miejsce; // works good
        //viewModel.Skleps = viewModel.Sklep_has_Miejsces.Where(i => i.MiejsceID == id.Value).Single().Sklep; //error
    }
        return View(viewModel);
}

1 Answer 1

1

From the looks of it, ProductIndexData.Skleps is an IEnumerable<Sklep> and you are attempting to assign a Sklep to it. This can be solved by changing your non-working line to the following:

viewModel.Skleps = viewModel.Sklep_has_Miejsces.Where(i => i.MiejsceID == id.Value).Select(s => s.Sklep);
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.