【发布时间】:2020-12-08 13:25:18
【问题描述】:
早安,
我有一个 ASP.NET MVC 项目,我正在使用实体框架和从数据库中自动生成的模型。我想向字段添加一些属性,但想将它们添加到 ViewModels 而不是 Models,因为 EF 会在刷新时覆盖这些属性。请告知此 ViewModel 的正确语法,因为我收到错误“无效的模型配置”。我想从 WorkOrder 模型生成 WorkOrderPartNo ViewModel
当前自动生成的 WorkOrder 模型:
namespace EMS.Models
{
using System;
using System.Collections.Generic;
public partial class WorkOrder
{
public WorkOrder()
{
this.WorkOrder1 = new HashSet<WorkOrder>();
}
public long ID { get; set; }
public string WONumber { get; set; }
public string ExtWONo { get; set; }
public string WO_Description { get; set; }
public Nullable<int> HierarchyObjectID { get; set; }
public Nullable<int> ProductiveUnitID { get; set; }
public Nullable<int> ComponentID { get; set; }
public Nullable<int> ComponentCodeID { get; set; }
public Nullable<int> PositionCodeID { get; set; }
public int ActivityTypeID { get; set; }
public int PackageID { get; set; }
public Nullable<long> ParentWO { get; set; }
public string Type { get; set; }
public string Priority { get; set; }
public Nullable<System.DateTime> BasicStart { get; set; }
public Nullable<System.DateTime> BasicFin { get; set; }
public Nullable<System.DateTime> SchedStart { get; set; }
public Nullable<System.DateTime> SchedFin { get; set; }
public System.DateTime RefDate { get; set; }
public Nullable<int> WorkGroupID { get; set; }
public Nullable<float> DurationHrs { get; set; }
public Nullable<float> ActWork { get; set; }
public string WOStatusID { get; set; }
public Nullable<int> ForecastItemID { get; set; }
public string IssueNo { get; set; }
public Nullable<int> PartID { get; set; }
public Nullable<double> Quantity { get; set; }
public Nullable<int> IssueUOM { get; set; }
public Nullable<decimal> ActTotSum { get; set; }
public Nullable<decimal> SumTotPlan { get; set; }
public string CurrencyID { get; set; }
public Nullable<int> AccountID { get; set; }
public bool Exclude { get; set; }
public bool Reviewed { get; set; }
public Nullable<System.DateTime> CreatedOn { get; set; }
public Nullable<System.DateTime> LastChangedOn { get; set; }
public string LastChangedBy { get; set; }
public bool Exported { get; set; }
public virtual ActivityType ActivityType { get; set; }
public virtual Package Package { get; set; }
public virtual PartMaster PartMaster { get; set; }
public virtual PositionCode PositionCode { get; set; }
public virtual WO_CalcUOM WO_CalcUOM { get; set; }
public virtual WOStatu WOStatu { get; set; }
public virtual ICollection<WorkOrder> WorkOrder1 { get; set; }
public virtual WorkOrder WorkOrder2 { get; set; }
public virtual Component Component { get; set; }
public virtual ComponentCode ComponentCode { get; set; }
public virtual HierarchyObject HierarchyObject { get; set; }
public virtual ForecastItem ForecastItem { get; set; }
public virtual Account Account { get; set; }
public virtual UOM_Procurement UOM_Procurement { get; set; }
public virtual ProductiveUnit ProductiveUnit { get; set; }
public virtual WorkGroup WorkGroup { get; set; }
}
}
给出错误的 WorkOrderPartNo ViewModel:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EMS.Models;
namespace EMS.ViewModels
{
using System;
using System.Collections.Generic;
public partial class WorkOrderPartNo : WorkOrder
{
public WorkOrderPartNo()
{
this.WorkOrder1 = new HashSet<WorkOrder>();
}
public new long ID { get; set; }
public new string WONumber { get; set; }
public new string ExtWONo { get; set; }
public new string WO_Description { get; set; }
public new Nullable<int> HierarchyObjectID { get; set; }
public new Nullable<int> ProductiveUnitID { get; set; }
public new Nullable<int> ComponentID { get; set; }
public new Nullable<int> ComponentCodeID { get; set; }
public new Nullable<int> PositionCodeID { get; set; }
public new int ActivityTypeID { get; set; }
public new int PackageID { get; set; }
public new Nullable<long> ParentWO { get; set; }
public new string Type { get; set; }
public new string Priority { get; set; }
public new Nullable<System.DateTime> BasicStart { get; set; }
public new Nullable<System.DateTime> BasicFin { get; set; }
public new Nullable<System.DateTime> SchedStart { get; set; }
public new Nullable<System.DateTime> SchedFin { get; set; }
public new System.DateTime RefDate { get; set; }
public new Nullable<int> WorkGroupID { get; set; }
public new Nullable<float> DurationHrs { get; set; }
public new Nullable<float> ActWork { get; set; }
public new string WOStatusID { get; set; }
public new Nullable<int> ForecastItemID { get; set; }
public new string IssueNo { get; set; }
[UIHint("ComboBox")]
public new Nullable<int> PartID { get; set; }
public new Nullable<double> Quantity { get; set; }
public new Nullable<int> IssueUOM { get; set; }
public new Nullable<decimal> ActTotSum { get; set; }
public new Nullable<decimal> SumTotPlan { get; set; }
public new string CurrencyID { get; set; }
public new Nullable<int> AccountID { get; set; }
public new bool Exclude { get; set; }
public new bool Reviewed { get; set; }
public new Nullable<System.DateTime> CreatedOn { get; set; }
public new Nullable<System.DateTime> LastChangedOn { get; set; }
public new string LastChangedBy { get; set; }
public new bool Exported { get; set; }
// public new virtual ActivityType ActivityType { get; set; }
// public new virtual Package Package { get; set; }
// public new virtual PartMaster PartMaster { get; set; }
// public new virtual PositionCode PositionCode { get; set; }
// public new virtual WO_CalcUOM WO_CalcUOM { get; set; }
// public new virtual WOStatu WOStatu { get; set; }
// public new virtual ICollection<WorkOrder> WorkOrder1 { get; set; }
// public new virtual WorkOrder WorkOrder2 { get; set; }
// public new virtual Component Component { get; set; }
// public new virtual ComponentCode ComponentCode { get; set; }
// public new virtual HierarchyObject HierarchyObject { get; set; }
// public new virtual ForecastItem ForecastItem { get; set; }
// public new virtual Account Account { get; set; }
// public new virtual UOM_Procurement UOM_Procurement { get; set; }
// public new virtual ProductiveUnit ProductiveUnit { get; set; }
// public new virtual WorkGroup WorkGroup { get; set; }
}
}
感谢您的帮助
【问题讨论】:
-
我不认为你把“新”放在属性的定义中。
标签: c# asp.net-mvc