Hello friends good morning, I have a problem with the Entity Framework more properly.
I have the following entity that comes from the db with entity framework
- namespace CapaDatos
- {
- using System;
- using System.Collections.Generic;
- public partial class tblCargo
- {
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
- public tblCargo()
- {
- this.tblEmpleados = new HashSet
(); - }
- public int Id { get; set; }
- public string Nombre_Cargo { get; set; }
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
- public virtual ICollection
tblEmpleados { get; set; } - }
- }
this is why I create another file on the same layer called OperationsCargos
Rename the class to tblCargo
- namespace CapaDatos
- {
- public partial class tblCargo
- {
- public static void Modificar(tblCargo tblCargo)
- {
- using (GourmetEntities db = new GourmetEntities())
- {
- try
- {
- db.Entry(tblCargo).State = EntityState.Modified;
- db.SaveChanges();
- }
- catch (Exception)
- {
- throw;
- }
- }
- }
- }
- }
this is the btn code
- private void TsbModificar_Click(object sender, EventArgs e)
- {
- objCargo.Id = int.Parse(TxtId.Text);
- objCargo.Nombre_Cargo = TxtCargo.Text;
- Cargo.Modificar(objCargo);
- MessageBox.Show("Registro con exito");
- }

Please can you help me find my mistake,
Thanks a lot
Ro
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rajanikant HawaldarPosted Apr 29, 2020, 2:26 AM