سلام استاد عزیز و گرامی مشکل این کد کجاست که اگه اینطوری بنوسم مشکل ایجاد میشه و نمیزاره ذخیره کنم
Project_DetailModel.ID_Project = Project_ManagementkModel.ID_Project;
Project_DetailModel.Title = texTitle.Text;
Project_DetailModel.unit =double.Parse(texunit.Text);
Project_DetailModel.cost_unit = double.Parse(texcost_unit.Text);
Project_DetailModel.overall_cost = (double.Parse(texunit.Text) * double.Parse(texcost_unit.Text));
Project_DetailModel.Description = texDescription.Text;
if (_ProjectDetail_ID == Guid.Empty)
{
Project_DetailModel.ID_ProjectDetail = Guid.NewGuid();
db.Project_DetailModels.Insert(Project_DetailModel);
db.Project_DetailModels.Save();
gridControlProject_Detail.DataSource = db.Project_DetailModels.Get(x => x.ID_Project == Project_ManagementkModel.ID_Project).ToList();
}
ولی وقتی که به اینصورت مینوسم مشکلی نداره
Project_DetailModel.ID_Project = Project_ManagementkModel.ID_Project;
Project_DetailModel.Title = texTitle.Text;
Project_DetailModel.unit =double.Parse(texunit.Text);
Project_DetailModel.cost_unit = double.Parse(texcost_unit.Text);
Project_DetailModel.overall_cost = (double.Parse(texunit.Text) * double.Parse(texcost_unit.Text));
Project_DetailModel.Description = texDescription.Text;
if (_ProjectDetail_ID == Guid.Empty)
{
Project_DetailModel.ID_ProjectDetail = Guid.NewGuid();
db.Project_DetailModels.Insert(Project_DetailModel);
db.Project_DetailModels.Save();
gridControlProject_Detail.DataSource = db.Project_DetailModels.Get(x => x.ID_Project == Project_ManagementkModel.ID_Project).ToList();
Project_DetailModel = new Project_Detail();
}
چرا برای ذخیره جدید رکورد باید بعد هر بار ذخیر یکبار این کار انجام بدم
Project_DetailModel = new Project_Detail();
متن خطا رو قرار بدید تا بررسی کنم
System.InvalidOperationException
HResult=0x80131509
Message=The property 'ID_ProjectDetail' is part of the object's key information and cannot be modified.
Source=EntityFramework
StackTrace:
at System.Data.Entity.Core.Objects.EntityEntry.DetectChangesInProperty(Int32 ordinal, Boolean detectOnlyComplexProperties, Boolean detectOnly)
at System.Data.Entity.Core.Objects.EntityEntry.DetectChangesInProperties(Boolean detectOnlyComplexProperties)
at System.Data.Entity.Core.Objects.ObjectStateManager.DetectChangesInScalarAndComplexProperties(IList`1 entries)
at System.Data.Entity.Core.Objects.ObjectStateManager.DetectChanges()
at System.Data.Entity.Core.Objects.ObjectContext.DetectChanges()
at System.Data.Entity.Internal.InternalContext.DetectChanges(Boolean force)
at System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)
at System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity)
at System.Data.Entity.DbSet`1.Add(TEntity entity)
at DataLayer.MyGenericRepository`1.InsertME(TEntity entity) in E:\TRMIS3\TRMIS3\DataLayer\MyGenericRepository.cs:line 60
at TRMIS3.Frm_Project_Management.ButSaveD_Click(Object sender, EventArgs e) in E:\TRMIS3\TRMIS3\TRMIS3\Add\Frm_Project_Management.cs:line 86
at System.Windows.Forms.Control.OnClick(EventArgs e)
at DevExpress.XtraEditors.BaseButton.OnClick(EventArgs e)
at DevExpress.XtraEditors.BaseButton.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at DevExpress.Utils.Controls.ControlBase.WndProc(Message& m)
at DevExpress.XtraEditors.BaseControl.WndProc(Message& msg)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at Clas_Settingscs.GetWaitForm(Form NameForm) in E:\TRMIS3\TRMIS3\TRMIS3\FRM_BASE\Cls\Clas_Settingscs.cs:line 25
at TRMIS3.Frm_Project_ManagementList.ButEditt_ButtonClick(Object sender, ButtonPressedEventArgs e) in E:\TRMIS3\TRMIS3\TRMIS3\List\Frm_Project_ManagementList.cs:line 40
at DevExpress.XtraEditors.Repository.RepositoryItemButtonEdit.RaiseButtonClick(ButtonPressedEventArgs e)
at DevExpress.XtraEditors.ButtonEdit.OnClickButton(EditorButtonObjectInfoArgs buttonInfo)
at DevExpress.XtraEditors.ButtonEdit.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at DevExpress.Utils.Controls.ControlBase.WndProc(Message& m)
at DevExpress.XtraEditors.TextEdit.WndProc(Message& msg)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at Clas_Settingscs.GetWaitForm(Form NameForm) in E:\TRMIS3\TRMIS3\TRMIS3\FRM_BASE\Cls\Clas_Settingscs.cs:line 25
at TRMIS3.Frm_Maim.barButtonItem8_ItemClick(Object sender, ItemClickEventArgs e) in E:\TRMIS3\TRMIS3\TRMIS3\FRM_BASE\Frm_Maim.cs:line 50
at DevExpress.XtraBars.BarItem.OnClick(BarItemLink link)
at DevExpress.XtraBars.BarButtonItem.OnClick(BarItemLink link)
at DevExpress.XtraBars.BarItemLink.OnLinkClick()
at DevExpress.XtraBars.BarButtonItemLink.OnLinkClick()
at DevExpress.XtraBars.BarItemLink.OnLinkAction(BarLinkAction action, Object actionArgs)
at DevExpress.XtraBars.BarButtonItemLink.OnLinkAction(BarLinkAction action, Object actionArgs)
at DevExpress.XtraBars.ViewInfo.BarSelectionInfo.ClickLink(BarItemLink link)
at DevExpress.XtraBars.ViewInfo.BarSelectionInfo.UnPressLink(BarItemLink link)
at DevExpress.XtraBars.Ribbon.Handler.BaseRibbonHandler.OnUnPressItem(DXMouseEventArgs e, RibbonHitInfo hitInfo)
at DevExpress.XtraBars.Ribbon.Handler.BaseRibbonHandler.OnUnPress(DXMouseEventArgs e, RibbonHitInfo hitInfo)
at DevExpress.XtraBars.Ribbon.Handler.RibbonHandler.OnUnPress(DXMouseEventArgs e, RibbonHitInfo hitInfo)
at DevExpress.XtraBars.Ribbon.Handler.BaseRibbonHandler.OnMouseUp(DXMouseEventArgs e)
at DevExpress.XtraBars.Ribbon.Handler.RibbonHandler.OnMouseUp(DXMouseEventArgs e)
at DevExpress.XtraBars.Ribbon.RibbonControl.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at DevExpress.Utils.Controls.ControlBase.WndProc(Message& m)
at DevExpress.XtraBars.Ribbon.RibbonControl.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at DevExpress.Utils.Drawing.Helpers.NativeMethods.UnsafeNativeMethods.DefSubclassProc(IntPtr hWnd, IntPtr Msg, IntPtr wParam, IntPtr lParam)
at DevExpress.Utils.Drawing.Helpers.Win32SubclasserFactory.Win32Subclasser.SubClassProcInner(IntPtr hWnd, IntPtr Msg, IntPtr wParam, IntPtr lParam, IntPtr uIdSubclass, IntPtr dwRefData)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at Clas_Settingscs.GetWaitForm(Form NameForm) in E:\TRMIS3\TRMIS3\TRMIS3\FRM_BASE\Cls\Clas_Settingscs.cs:line 25
at TRMIS3.Program.Main() in E:\TRMIS3\TRMIS3\TRMIS3\FRM_BASE\Cls\Program.cs:line 48
متن کامل خطا
The property 'ID_ProjectDetail' is part of the object's key information and cannot be modified.
استاد مشکل چیست؟
استاد میشه بگید مشکلم کجاست؟