You must Sign In to post a response.
  • Category: LINQ

    Perform update operation in LINQ (urgent)

    hi all,

    in my project i am maintaining three entities called route, routecountry and routeday.relationship for route to route country and route to route day are one to many.

    i did insert operation using linq as follows,

    code in UI

    europeModel.Route route = new europeModel.Route();
    System.Data.Linq.EntitySet<europeModel.Route_Country> routeCountryList = new System.Data.Linq.EntitySet<europeModel.Route_Country>();
    System.Data.Linq.EntitySet<europeModel.Route_Day> routeDayList = new System.Data.Linq.EntitySet<europeModel.Route_Day>();

    europeModel.Route_Country arrCountry = new europeModel.Route_Country();
    europeModel.Route_Country desCountry = new europeModel.Route_Country();

    arrCountry.RefCityId = ddlArrCity.SelectedIndex;
    arrCountry.IsArrival = true;

    desCountry.RefCityId = ddlDepCity.SelectedIndex;
    desCountry.IsArrival = false;

    routeCountryList.Add(arrCountry);
    routeCountryList.Add(desCountry);
    if (GridView1.Rows.Count > 0)
    {
    for (int i = 0; i < GridView1.Rows.Count; i++)
    {
    europeModel.Route_Day routeDay = new europeModel.Route_Day();
    routeDay.OperatedDate_Time = Convert.ToDateTime(_sampleData.Rows[i]["OperateDate"].ToString());
    routeDay.Capacity = Convert.ToInt32(_sampleData.Rows[i]["Capacity"].ToString());
    routeDay.Price = Convert.ToDecimal(_sampleData.Rows[i]["Price"].ToString());


    routeDayList.Add(routeDay);
    }
    }

    route.RouteCode = txtRouteCode.Text;
    route.RouteName = txtRouteName.Text;
    route.Route_Countries = routeCountryList;
    route.Route_Days = routeDayList;


    code in BL Layer

    using (EuropeBus.Model.Domain.EuropeBusDataContext data = new Model.Domain.EuropeBusDataContext())
    {

    data.Routes.InsertOnSubmit(route);
    data.SubmitChanges();


    }



    I can view inserted route and route days and route country into UI.my question is,
    how do i update route days and route country details when i did change or add new line to them

    thanks
  • #745538
    hi chaminda,

    first of all you select column to update in a table exam. days and country in table route and datecontax is data

    select query in linq..

    var query=from r in data.Routewhere r.RouteCode=2 select r;
    // Than create teble type oblect

    Route ro=new Route();
    ro.Route_Countries=new_contery_name;
    ro.Route_Days =new_day_value;

    data.SubmitChanges();//update for table


    Surendra Sharma


  • Sign In to post your comments