用LinqToExcel导入数据 – 只读属性

我试图使用LinqToExcel从Excel中导入数据。 我在模型类中只有很less的只读属性。 当我尝试将它们映射到excel列时,它们会失败,并显示以下错误。 另外,当我从Excel中删除这些列,它没有价值的工作正常。

找不到方法“总计”。

型号:预算

[Required] [Display(Name = "Room Type")] public int RoomTypeID { get; set; } [ForeignKey("RoomTypeID")] public virtual RoomType RoomType { get; set; } public decimal Pair { get; set; } [ExcelColumn("Cost per Room*")] public decimal CostPerRoom { get; set; } [NotMapped] [ExcelColumn("Total")] [Display(Name = "Total")] public decimal Total { get { if (this.RoomType != null) { return this.CostPerRoom * this.RoomType.RoomTypeQty * this.Pair; } else { return 0; } } } 

预算控制器:

  public ActionResult ReadFromExcel() { var file = Request.Files[0]; if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Uploads/"), fileName); file.SaveAs(path); var excel = new ExcelQueryFactory(path); excel.DatabaseEngine = DatabaseEngine.Ace; excel.TrimSpaces = LinqToExcel.Query.TrimSpacesType.Both; var budgets = from c in excel.Worksheet<Budget>("WorksheeName") select c; foreach (var item in budgets) // This is where it generates the error. { } } 

我如何克服这一点?