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.2k
Delete and save in table from Entity Framework
Apr 29 2020 12:56 PM
Hello friends, good morning.
I have the following drawback, a many-to-many table.
works perfectly up to here, I hope it is well implemented
I show the image
I enter this data in this way
now i want to remove a rule from a certain profile
in this case remove the Employee profile, Create Client and Edit Client. The idea I have is to delete all the rules assigned to the employee and then again enter the new rules (In this case only one rule)
I did this method
public
static
void
InsertarPerfilRegla(tbltransPerfilRegla tbltransPerfilRegla)
{
using
(GourmetEntities db =
new
GourmetEntities())
{
db.tbltransPerfilReglas.RemoveRange(db.tbltransPerfilReglas.Where(x => x.Perfil_Id == tbltransPerfilRegla.Perfil_Id));
db.SaveChanges();
db.tbltransPerfilReglas.Add(tbltransPerfilRegla);
db.SaveChanges();
}
}
When I only run the code block
db.tbltransPerfilReglas.RemoveRange(db.tbltransPerfilReglas.Where(x => x.Perfil_Id == tbltransPerfilRegla.Perfil_Id));
db.SaveChanges();
Works correctly
But when I run both codes it shows me an error
This is the code in my Button
private
void
TsbGuardar_Click(
object
sender, EventArgs e)
{
tbltransPerfilRegla tbltransPerfilRegla =
new
tbltransPerfilRegla();
using
(GourmetEntities db =
new
GourmetEntities())
{
tbltransPerfilRegla.Perfil_Id = (
int
)CboPerfiles.SelectedValue;
foreach
(DataGridViewRow row
in
DatagridViewPerfilRegla.Rows)
{
if
((
bool
)row.Cells[
"Selected"
].Value)
{
//MessageBox.Show(row.Cells[1].Value.ToString());
tbltransPerfilRegla.Regla_Id = (
int
)row.Cells[1].Value;
}
tbltransPerfilRegla.InsertarPerfilRegla(tbltransPerfilRegla);
}
}
}
Please can you help me to solve this problem that I have, or can you tell me another way to do this please.
I thank you very much
Rob
Reply
Answers (
2
)
Dividing the data in text file into smaller chunks
How can i make duplicate controls in c#?