Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to make delete row from table using linq

how to make delete row from table using linq

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdatabaselinqarchitecture
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ahmed_sa
    wrote on last edited by
    #1

    In my Relation i have two tables relation (one to many) table country Id (primary key) Countryname table City Id (primary key) Cityname Countryid (forign key) I have controller City have the following function

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using LinqProject.Models;
    namespace LinqProject.Controllers
    {
    public class CityController : Controller
    {
    mytaskdbEntities db = new mytaskdbEntities();

    // GET: City
    public ActionResult List()
    {
    return View(db.Cities.ToList());
    }

    and in view of List as following

    <body>

    @foreach (var item in Model)
    {

    }

    @item.Cityname

    @item.Country.Countryname

    </body>

    What i need actually adding delete button to view of list of city and i can delete city when click button delete how to do deleting record by linq the final result as following USA NEWYORK DELETEBUTTON USA WASHINTON DELETEBUTTON FRANCE PARIS DELETEBUTTON when click delete button for row USA NEWYORK it will delete and remaining two record USA WASHINTON DELETEBUTTON FRANCE PARIS DELETEBUTTON

    J 1 Reply Last reply
    0
    • A ahmed_sa

      In my Relation i have two tables relation (one to many) table country Id (primary key) Countryname table City Id (primary key) Cityname Countryid (forign key) I have controller City have the following function

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.Web.Mvc;
      using LinqProject.Models;
      namespace LinqProject.Controllers
      {
      public class CityController : Controller
      {
      mytaskdbEntities db = new mytaskdbEntities();

      // GET: City
      public ActionResult List()
      {
      return View(db.Cities.ToList());
      }

      and in view of List as following

      <body>

      @foreach (var item in Model)
      {

      }

      @item.Cityname

      @item.Country.Countryname

      </body>

      What i need actually adding delete button to view of list of city and i can delete city when click button delete how to do deleting record by linq the final result as following USA NEWYORK DELETEBUTTON USA WASHINTON DELETEBUTTON FRANCE PARIS DELETEBUTTON when click delete button for row USA NEWYORK it will delete and remaining two record USA WASHINTON DELETEBUTTON FRANCE PARIS DELETEBUTTON

      J Offline
      J Offline
      John C Rayan
      wrote on last edited by
      #2

      You can add button control with command 'delete' in the buttons. When you click pass the id of city to be deleted to the controller. In the controller you need to receive two parameters command and id of the city. What's your issue ?

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups