none
EntityFramework - DatabaseContext -> just 3 tables are returning nothing RRS feed

  • Question

  • Hi all, 

    I'm Gerard and I'm dealing with a project which contains MVC, WPF and entity framework. 

    For now, on our website, I have build a check like this:

    @if(Model.Count != 0) { @Html.HiddenFor(m => m.First().ID)

    //Code here

    The problem is that for some reason the model.count is always 0. Connection is OK, and I can get other data via the datacontext as wel; but not for 3 tables. 

    For example:

           

     
    //----------------------
           
    // Operators Section
           
    //----------------------
           
    public
    ActionResult Operators() 
    {
       ViewBag.tab1Selection = 1;
       ViewBag.tab2Selection = 3;
    
       db = new DatabaseContext();
               
          List<CooltankParameters> temp = db.CooltankParameters.ToList();
               
          List<CooltankData> temp2 = db.CooltankData.ToList();
               
          List<CooltankComposition> temp3 = db.CooltankComposition.ToList();
               
          List<Recipe> temp4 = db.Recipes.ToList();
    
               
    return View("Operators", db.Operators.ToList());
           
    }


    So only temp4 has something as result.. 

    What do you think which will cause this strange behaiviour?

    Thanks in advance for answering my question. 

    Kind regards, 

    Gerard




    • Edited by NGerard Thursday, April 17, 2014 7:15 AM
    Thursday, April 17, 2014 7:10 AM

All replies

  • Hello,

    I am not very familiar with MVC, but as far as I know, this Model.Count comes from the value of “return View("Operators", db.Operators.ToList());”, it does not have association with the temp4. So please check whether the db.Operators.ToList() has data.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, April 18, 2014 2:10 AM
    Moderator
  • Hi, 

    Thanks for the reply. The temp4 contains data.. so the db.Recipes.ToList(); too.
    Unfortunately the  db.CooltankParameters.ToList(); is empty.. : (

    Tomorrow I will go further with testing, and setup a test environment or something.. 

    Let's see what happens then. 

    Kind regards, Gerard

    Wednesday, April 23, 2014 7:39 PM
  • Hello NGerard,

    >> Tomorrow I will go further with testing, and setup a test environment or something.. Let's see what happens then.

    Have you found something new?

    >> Unfortunately the  db.CooltankParameters.ToList(); is empty.. : (

    I am confused why it will be empty, this is caused by only there is no data in database. So please check if there is data in db.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, April 25, 2014 7:03 AM
    Moderator
  • Yeah, Fred Bao, 

    You are right. There was no data in the database (headbang). 

    I was pretty sure (99%) that there was data. But probably I was looking @an old performed query result. 

    Sorry for all the disturbtion. And of course thanks for the help!

    Kind regards, Gerard

    Tuesday, May 13, 2014 10:45 AM