TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
RobertoCarlos Melgar
1.6k
159
10.3k
The entity type Cargo is not part of the model for the curre
Apr 27 2020 11:53 AM
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<tblEmpleado>();
}
public
int
Id {
get
;
set
; }
public
string
Nombre_Cargo {
get
;
set
; }
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Usage"
,
"CA2227:CollectionPropertiesShouldBeReadOnly"
)]
public
virtual
ICollection<tblEmpleado> tblEmpleados {
get
;
set
; }
}
}
As you will see the class is partial
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 to have my methods in the same layer but in another file, that if I delete the entity my methods are lost
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"
);
}
when i run the application it shows me the following error
Please can you help me find my mistake,
Thanks a lot
Ro
Reply
Answers (
1
)
OnUploadedComplete not firing
Upload a image using multipart.