[RESOLVED]Accessing model object that's not part of the DBContext

Hi All,

I have a simple reservation system and trying to get a usage for its resource objects. My goal is to take data from PODPOject… Do some data crunching(in controller) and convert it to POCReportByCluster object, then pass it to the view.

However, when I am not able to access POCReportByCluster property (see line 6 in Reports Controller ). Please help.

Is there a relationship between your PODPOject and your POCReportByCluster objects? If so and you need to include this relationship when you pull a particular entity from your context, you can use the Include() method to populate it :

var data = context.PODPOjects.Include("POCReportByCluster").Where(p => p.Id == "xxx");

This is a very basic example and may not be applicable in your situation. However another option to consider would be to create a constructor for your POCReportByCluster object that accepts a PODOject object. 

// Example constructor
public partial POCReportByCluster(PODOject podoject)
{
      // Populate your properties for a POCReportByCluster object from the podoject here
}

This way if your View needs to accept a POCReportByCluster object, you can perform your logic and then pass it in to create a new POCReportByCluster object and then pass it to the View :

public ActionResult YourAction()
{
       // Get your PODPOject here
       var podpoOject = GetItHere();

       // Apply some logic here

       // Create a POCReportByCluster object (using your PODPOject)
       var model = new POCReportByCluster(podpoOject);

       // Pass it to your view
       return View(model);
}

Leave a Reply