In my method, I have this query:
var query =
_db.STEWARDSHIP
.OrderBy(r => r.SITE.SITE_NAME)
.Where(r => SiteId == null || r.SITE_ID == iSiteId)
.Where(r => SiteTypeId == null || r.SITE.SITE_TYPE_VAL.SITE_TYPE_ID == iSiteTypeId)
.Where(r => EcoregionId == null || r.SITE.ECOREGION_VAL.ECOREGION_ID == iEcoregionId)
.Where(r => ConservationAreaId == null || r.SITE.CONSERVATION_AREA_VAL.CONSERVATION_AREA_ID == iConservationAreaId)
.Where(r => VisitTypeId == null || r.VISIT_TYPE_VAL.VISIT_TYPE_ID == iVisitTypeId)
.Where(r => Staff == null || r.STAFF.Contains(sStaff))
.Where(r => Comment == null || r.VISIT_COMMENTS.Contains(sComment))
.Select(r => new SiteVisitDetails
{
Id = r.STEWARDSHIP_ID,
Name = r.SITE.SITE_NAME,
VisitType = r.VISIT_TYPE_VAL.VISIT_TYPE_DESC,
VisitDate = r.VISIT_DATE
});
This fails with the error:
SiteVisitDetails does not contain a constructor that takes 0 arguments
Here the class:
public class SiteVisitDetails : ISiteVisitDetails
{
private int _id;
private string _name;
private DateTime _visitDate;
private string _visitType;
public SiteVisitDetails(int Id, string Name, DateTime VisitDate,
string VisitType)
{
_id = Id;
_name = Name;
_visitDate = VisitDate;
_visitType = VisitType;
}
public int Id
{
get { return _id; }
set { _id = value; }
}
public string Name
{
get { return _name; }
set { _name = value; }
}
public DateTime VisitDate
{
get { return _visitDate; }
set { _visitDate = value; }
}
public string VisitType
{
get { return _visitType; }
set { _visitType = value; }
}
public string getShortVisitDate()
{
return _visitDate.ToShortDateString();
}
}
The Interface:
interface ISiteVisitDetails
{
int Id { get; set; }
string Name { get; set; }
DateTime VisitDate { get; set; }
string VisitType { get; set; }
string getShortVisitDate;
}
I don't understand why I would need a constructor that takes 0 arguments. Can somebody help me understand?
Thanks.