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;








0















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();











share|improve this question
























  • 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

















0















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();











share|improve this question
























  • 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













0












0








0








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();











share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 is Roles 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











  • 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
















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












1 Answer
1






active

oldest

votes


















0














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.






share|improve this answer























    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
    );



    );













    draft saved

    draft discarded


















    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









    0














    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.






    share|improve this answer



























      0














      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.






      share|improve this answer

























        0












        0








        0







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 8 at 19:37









        melkisadekmelkisadek

        7791831




        7791831





























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

            Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved