Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4337650
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:58:24+00:00 2026-05-21T10:58:24+00:00

I use ASP.NET MVC3 and as Data layer LinqToSql. I`m a little bit confuse

  • 0

I use ASP.NET MVC3 and as Data layer LinqToSql.
I`m a little bit confuse how can i edit an entity.

public ActionResult Edit(int id)
{
    var product = _repository.GetById(id);
    return View(product);
}


[HttpPost]
public ActionResult Edit(Product product)
{
    if (ModelState.IsValid)
    {
        _repository.EditProduct(product);
        return RedirectToAction("Index");
    }
    return View();
}

Variable product in Edit() is ok, but after editing view the variable passed in [HttpPost] Edit
has null in link properties and seems to be detached from my DataContext.
And also what code should i execute in EditProduct method to update entity?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T10:58:25+00:00Added an answer on May 21, 2026 at 10:58 am

    I am assuming in your repository you have an object for your data context. In your EditProduct call you should have something like:

    Product prod = dataContext.Products.Single(p=>p.ProductID == product.ProductID);
    
    prod.PropertyA = product.PropertyA;
    prod.PropertyB = product.PropertyB;
    dataContext.SubmitChanges();
    

    You can also attach the product coming in and save (if you have a timestamp column):

    dataContext.Products.Attach(product,true);
    dataContext.SubmitChanges();
    

    If you don’t have a timestamp column then L2S will throw an error about not being able to check it’s state.

    An entity can only be attached as modified without original state if it declares a version member or does not have an update check policy.

    If you add a timestamp column to your DB then L2S can do the above.

    Here’s a deeper explanation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In ASP.NET MVC3 projects, is it faster, more secure, to use Entity Framework (with
In an ASP.NET MVC3 application, I'm trying to use jQuery to make an asynchronous
I'm in Asp.net MVC3 environment, and I use Advantage Database 9.1. and I want
From Entity Framework using ASP .NET MVC 3.0, is it possible to use a
I've got the following ActionResult in a ASP.NET MVC 3 project: public ActionResult Index(string
I'm building a Asp.net MVC3 aplication (with Razor) and I have a Data Base
Introduction I'm using ASP.Net MVC3. My Controllers talk to a service layer, and the
I'm working on a asp.net mvc3 solution that has 3 projects Data, Service, and
I'm working on a rather large Asp.net MVC3 project and would like to use
I have an ASP.NET MVC3 web application with UI, Business (entities), and Data (DbContext)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.