質問

I have read several questions and answers on this topic, it seems to be a fairly common topic, but none have so far been able to help me.

I am using Visual Studio 2013 and entity framework and trying to create a local report from an object and display it in the reportviewer.

When I run it the report headers show but no data despite the fact that my GetConstraints() method is called and runs without a problem.

The model for the data has been kept fairly simple:

public class ConstraintDataModel
{
    public string name { get; set; }
    public int interval { get; set; }
    public string complianceEntity { get; set; }
    public string inspectionEntity { get; set; }
    public string nominalValue { get; set; }
    public int taskID { get; set; }
    public string installations { get; set; }
    public int groupTask { get; set; }
    public string lastInspectionDate { get; set; }
    public string nextInspectionDate { get; set; }
    public int missed { get; set; }
    public string rating { get; set; }
}

As has the method for returning it:

public static List<ConstraintDataModel> GetConstraints()
    {
        List<ConstraintDataModel> constraintList = new List<ConstraintDataModel>();
        List<ICMConstraint> constraints = (List<ICMConstraint>)ctx.ICMConstraints.Where(cust => cust.CustomerID.Equals(1001)).ToList();

        foreach (ICMConstraint constraint in constraints)
        {
            ConstraintDataModel constraintsModel = new ConstraintDataModel();
            constraintsModel.taskID = constraint.ConstraintID;
            constraintsModel.name = constraint.Name;
            constraintsModel.complianceEntity = GetEntityName(constraint.ComplianceEntityID);
            constraintsModel.inspectionEntity = GetEntityName(constraint.InspectionEntityID);
            constraintsModel.installations = GetInstallations(constraint.ConstraintID);
            constraintsModel.interval = constraint.Interval;
            constraintsModel.nextInspectionDate = constraint.NextInspectionDate.ToShortDateString();
            constraintsModel.missed = constraint.MissedInspections;
            constraintsModel.nominalValue = constraint.NominalValue;
            constraintsModel.rating = GetConstraintRating(constraint.ConstraintID);

        }

        return constraintList;
    }

I have followed a few tutorials and haven't deviated from them. I have also tried explicitly binding the data on Page_Load but that doesn't help.

I am not sure what other code to post so if anything else is need just say.

役に立ちましたか?

解決

Don't you need to add the object to the list you are returning:

}
return constraintList;

to this:

    constraintList.Add(constraintsModel);
}
return constraintList;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top