Refactor Code

  • Gravatar
    Update Object using Linq & ObjectDataSource

    by osmansays on 5/17/2008 5:42:30 PM
  • I have an ObjectDataSet to in my aspx page for updating through my BLL classes ,it passes the selected object to be updated to my update method in attached here,I think it is the ugliest code ever. I tried to assign the objects directly but it didn't work? Any ideas to let this code looks nice!!
  • public static bool UpdateDriver(Driver _newdriver)
    {
    myDALDataContext DB = new myDALDataContext();
    Driver oldDriver = (from driver in DB.Drivers
    where _newdriver.DriverID == driver.DriverID
    select driver).Single();
    oldDriver.DrivingLicenseNumber = _newdriver.DrivingLicenseNumber;
    oldDriver.DrivingLicenseTypID = _newdriver.DrivingLicenseTypID;
    oldDriver.IdentityExpireDate = _newdriver.IdentityExpireDate;
    oldDriver.IdentityNumber = _newdriver.IdentityNumber;
    oldDriver.IdentityTypeID = _newdriver.IdentityTypeID;
    oldDriver.JobID = _newdriver.JobID;
    oldDriver.MobileNumber = _newdriver.MobileNumber;
    oldDriver.Name = _newdriver.Name;

    oldDriver.Data.Linq.ChangeSet change = DB.GetChangeSet();
    DB.SubmitChanges();
    return (change.Updates.Count >= 1);
    }
  • Refactor it!
  • Gravatar
    This is one of the big issues with LINQ to SQL. I wrote a very detailed post on my blog that talks about issues related to DataContext and how to resolve them. You can check it out using the following link: http://geekswithblogs.net/AzamSharp/archive/2008/05/17/122222.aspx
    by azamsharp on 5/17/2008 6:53:03 PM
Please log in to refactor the code! Login