Update/Edit an Entry in C# CRUD Operations Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How do I calculate someone's age in C#?Calculate relative time in C#What is the difference between String and string in C#?Hidden Features of C#?Calling the base constructor in C#Cast int to enum in C#How do you give a C# Auto-Property a default value?How do I enumerate an enum in C#?What are the correct version numbers for C#?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?
Can you use the Shield Master feat to shove someone before you make an attack by using a Readied action?
Is safe to use va_start macro with this as parameter?
Why are there no cargo aircraft with "flying wing" design?
Generate an RGB colour grid
What does "lightly crushed" mean for cardamon pods?
Do square wave exist?
What font is "z" in "z-score"?
Crossing US/Canada Border for less than 24 hours
Do jazz musicians improvise on the parent scale in addition to the chord-scales?
Is this homebrew Lady of Pain warlock patron balanced?
What do you call the main part of a joke?
2001: A Space Odyssey's use of the song "Daisy Bell" (Bicycle Built for Two); life imitates art or vice-versa?
Chinese Seal on silk painting - what does it mean?
How to compare two different files line by line in unix?
When a candle burns, why does the top of wick glow if bottom of flame is hottest?
What would be the ideal power source for a cybernetic eye?
Why wasn't DOSKEY integrated with COMMAND.COM?
Is it common practice to audition new musicians one-on-one before rehearsing with the entire band?
Why are both D and D# fitting into my E minor key?
How to react to hostile behavior from a senior developer?
Around usage results
Where are Serre’s lectures at Collège de France to be found?
Should I use a zero-interest credit card for a large one-time purchase?
How to Make a Beautiful Stacked 3D Plot
Update/Edit an Entry in C# CRUD Operations
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How do I calculate someone's age in C#?Calculate relative time in C#What is the difference between String and string in C#?Hidden Features of C#?Calling the base constructor in C#Cast int to enum in C#How do you give a C# Auto-Property a default value?How do I enumerate an enum in C#?What are the correct version numbers for C#?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to edit a RoleName
in my Roles
table. Everything is working except I am getting errors that there is no definition for the Entry
and the SaveChanges
methods. I have using
statements for both System.Data.Entity
and EntityFramework
so I am not sure what the issue is. I'm pretty sure that I have all the correct packages and references.
//Get Edit
[HttpGet]
public ActionResult Edit(Roles model)
return View();
//Put Edit
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(Comtrex_ICU.Models.Roles model, int RoleId,
Roles RoleName)
try
Roles db = new Roles();
db.Entry(RoleName).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("RolesIndex");
catch
return View();
c# asp.net model-view-controller crud
add a comment |
I am trying to edit a RoleName
in my Roles
table. Everything is working except I am getting errors that there is no definition for the Entry
and the SaveChanges
methods. I have using
statements for both System.Data.Entity
and EntityFramework
so I am not sure what the issue is. I'm pretty sure that I have all the correct packages and references.
//Get Edit
[HttpGet]
public ActionResult Edit(Roles model)
return View();
//Put Edit
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(Comtrex_ICU.Models.Roles model, int RoleId,
Roles RoleName)
try
Roles db = new Roles();
db.Entry(RoleName).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("RolesIndex");
catch
return View();
c# asp.net model-view-controller crud
Could you please provide the definition of Roles class. It seems to that compiler was unable to find two methods in Roles class: Entry and SaveChanges
– lerthe61
Mar 8 at 19:15
Why does your POST Edit signature have two instances of Roles being passed into it? What isRoles RoleName
and how is it being resolved?
– melkisadek
Mar 8 at 19:45
add a comment |
I am trying to edit a RoleName
in my Roles
table. Everything is working except I am getting errors that there is no definition for the Entry
and the SaveChanges
methods. I have using
statements for both System.Data.Entity
and EntityFramework
so I am not sure what the issue is. I'm pretty sure that I have all the correct packages and references.
//Get Edit
[HttpGet]
public ActionResult Edit(Roles model)
return View();
//Put Edit
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(Comtrex_ICU.Models.Roles model, int RoleId,
Roles RoleName)
try
Roles db = new Roles();
db.Entry(RoleName).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("RolesIndex");
catch
return View();
c# asp.net model-view-controller crud
I am trying to edit a RoleName
in my Roles
table. Everything is working except I am getting errors that there is no definition for the Entry
and the SaveChanges
methods. I have using
statements for both System.Data.Entity
and EntityFramework
so I am not sure what the issue is. I'm pretty sure that I have all the correct packages and references.
//Get Edit
[HttpGet]
public ActionResult Edit(Roles model)
return View();
//Put Edit
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(Comtrex_ICU.Models.Roles model, int RoleId,
Roles RoleName)
try
Roles db = new Roles();
db.Entry(RoleName).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("RolesIndex");
catch
return View();
c# asp.net model-view-controller crud
c# asp.net model-view-controller crud
edited Mar 8 at 19:15
Lews Therin
2,80111641
2,80111641
asked Mar 8 at 19:03
Megan MeluskeyMegan Meluskey
287
287
Could you please provide the definition of Roles class. It seems to that compiler was unable to find two methods in Roles class: Entry and SaveChanges
– lerthe61
Mar 8 at 19:15
Why does your POST Edit signature have two instances of Roles being passed into it? What isRoles RoleName
and how is it being resolved?
– melkisadek
Mar 8 at 19:45
add a comment |
Could you please provide the definition of Roles class. It seems to that compiler was unable to find two methods in Roles class: Entry and SaveChanges
– lerthe61
Mar 8 at 19:15
Why does your POST Edit signature have two instances of Roles being passed into it? What isRoles RoleName
and how is it being resolved?
– melkisadek
Mar 8 at 19:45
Could you please provide the definition of Roles class. It seems to that compiler was unable to find two methods in Roles class: Entry and SaveChanges
– lerthe61
Mar 8 at 19:15
Could you please provide the definition of Roles class. It seems to that compiler was unable to find two methods in Roles class: Entry and SaveChanges
– lerthe61
Mar 8 at 19:15
Why does your POST Edit signature have two instances of Roles being passed into it? What is
Roles RoleName
and how is it being resolved?– melkisadek
Mar 8 at 19:45
Why does your POST Edit signature have two instances of Roles being passed into it? What is
Roles RoleName
and how is it being resolved?– melkisadek
Mar 8 at 19:45
add a comment |
1 Answer
1
active
oldest
votes
As you don't appear to be calling them from a repository, Entry
and SaveChanges
are methods belonging to your EntityFramework Entities.
You're trying to call them from an instance of Roles
.
You need to instantiate your Entities as db
.
Instead of the following:
Roles db = new Roles();
You should do this (where Entities is the name you've given your entities):
Entities db = new Entities();
You can now find the Role you want to edit by using Find
:
var editRole = db.Roles.Find(RoleId);
Then you need to map your edited properties and then make your update.
You should instantiate your entities in the constructor of either the Controller or a service repository rather than each time you need it, but the example above should point you in the right direction.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069446%2fupdate-edit-an-entry-in-c-sharp-crud-operations%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As you don't appear to be calling them from a repository, Entry
and SaveChanges
are methods belonging to your EntityFramework Entities.
You're trying to call them from an instance of Roles
.
You need to instantiate your Entities as db
.
Instead of the following:
Roles db = new Roles();
You should do this (where Entities is the name you've given your entities):
Entities db = new Entities();
You can now find the Role you want to edit by using Find
:
var editRole = db.Roles.Find(RoleId);
Then you need to map your edited properties and then make your update.
You should instantiate your entities in the constructor of either the Controller or a service repository rather than each time you need it, but the example above should point you in the right direction.
add a comment |
As you don't appear to be calling them from a repository, Entry
and SaveChanges
are methods belonging to your EntityFramework Entities.
You're trying to call them from an instance of Roles
.
You need to instantiate your Entities as db
.
Instead of the following:
Roles db = new Roles();
You should do this (where Entities is the name you've given your entities):
Entities db = new Entities();
You can now find the Role you want to edit by using Find
:
var editRole = db.Roles.Find(RoleId);
Then you need to map your edited properties and then make your update.
You should instantiate your entities in the constructor of either the Controller or a service repository rather than each time you need it, but the example above should point you in the right direction.
add a comment |
As you don't appear to be calling them from a repository, Entry
and SaveChanges
are methods belonging to your EntityFramework Entities.
You're trying to call them from an instance of Roles
.
You need to instantiate your Entities as db
.
Instead of the following:
Roles db = new Roles();
You should do this (where Entities is the name you've given your entities):
Entities db = new Entities();
You can now find the Role you want to edit by using Find
:
var editRole = db.Roles.Find(RoleId);
Then you need to map your edited properties and then make your update.
You should instantiate your entities in the constructor of either the Controller or a service repository rather than each time you need it, but the example above should point you in the right direction.
As you don't appear to be calling them from a repository, Entry
and SaveChanges
are methods belonging to your EntityFramework Entities.
You're trying to call them from an instance of Roles
.
You need to instantiate your Entities as db
.
Instead of the following:
Roles db = new Roles();
You should do this (where Entities is the name you've given your entities):
Entities db = new Entities();
You can now find the Role you want to edit by using Find
:
var editRole = db.Roles.Find(RoleId);
Then you need to map your edited properties and then make your update.
You should instantiate your entities in the constructor of either the Controller or a service repository rather than each time you need it, but the example above should point you in the right direction.
answered Mar 8 at 19:37
melkisadekmelkisadek
7791831
7791831
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069446%2fupdate-edit-an-entry-in-c-sharp-crud-operations%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Could you please provide the definition of Roles class. It seems to that compiler was unable to find two methods in Roles class: Entry and SaveChanges
– lerthe61
Mar 8 at 19:15
Why does your POST Edit signature have two instances of Roles being passed into it? What is
Roles RoleName
and how is it being resolved?– melkisadek
Mar 8 at 19:45