Hi Team
I am experience this problem below and my table definition is as follows;
- // Model
- public class eNtsaRegForm
- {
- [Key]
- public int Id { get; set; }
- public string Title { get; set; }
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public string Position { get; set; }
- public string Company { get; set; }
- public string StreetAddress { get; set; }
- public string StreetAddressLine { get; set; }
- public string City { get; set; }
- public string StateProvince { get; set; }
- public int ZipCode { get; set; }
- public string Country { get; set; }
- public string Email { get; set; }
- [Required(ErrorMessage = " This field is required")]
- public int CellNumber { get; set; }
- public string DietaryRequirements { get; set; }
- }
- // Controller
- public ActionResult Download_XMLReport()
- {
- var _db = new eNtsaRegistration();
- var data = (from q in _db.Training select new eNtsaRegForm {
- FirstName = q.FirstName
- }).ToList(); // Error is here it can not be constructed to Linq
- ReportDocument rpt = new ReportDocument();
- rpt.Load(Server.MapPath("~/Reports/uYiloReporting.rpt"));
- rpt.SetDataSource(data);
- Response.Buffer = false;
- Response.ClearContent();
- Response.ClearHeaders();
- try
- {
- Stream stream = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
- stream.Seek(0, SeekOrigin.Begin);
- return File(stream, "application/excel", "eNtsaRegistrationForm.excel");
- }
- catch
- {
- throw;
- //return View();
- }
- }
Jenith ThakkarPosted Jul 22, 2020, 7:03 AM
You cannot (and should not be able to) project onto a mapped entity. You can, however, project onto an anonymous type
So create One more Model and use that like below