0
public void DependentUpdateManScheme(int DependentupdID, string EmployeeID, string Name, string Surname, string IDCardNo, string ContactNo, DateTime BirthDate, DateTime StartDate, DateTime EndDate, string Relation, double Payment)
        {
            HealthCareSystem.DataClassesDataContext db = new HealthCareSystem.DataClassesDataContext();

        var z = (from d in db.Dependents
                 where d.EmployeeID.Equals(EmployeeID)
                 join r in db.Relations on d.RelationID equals r.RelationID
                 select new DependentsX { DependentID = d.DependentID, EmployeeID = d.EmployeeID, Name = d.Name, Surname = d.Surname, IDCardNo = d.IDCardNo, ContactNo = d.ContactNo, BirthDate = d.BirthDate, StartSchemeDate = d.StartDate, EndSchemeDate = d.EndDate, RelationType = r.Type, Payment = d.Payment });

        List<DependentsX> oldList = z.ToList();
          foreach (DependentsX dep in oldList)
        {
            dep.DependentID = DependentupdID;
            dep.EmployeeID = EmployeeID;
            dep.Name = Name;
            dep.Surname = Surname;
            dep.IDCardNo = IDCardNo;
            dep.ContactNo = ContactNo;
            dep.BirthDate = BirthDate;
            dep.StartSchemeDate = StartDate;
            dep.EndSchemeDate = EndDate;
            dep.RelationID = Convert.ToInt32(Relation);
            dep.Payment = Payment;

            db.SubmitChanges();
        }
4

1 回答 1

0

DependentsX是您要更新的对象的类型。这是在 LINQ Select 表达式中作为未附加到上下文的新对象创建的。上下文没有看到任何要更新的内容,因此它无法更新任何内容。

您需要更新 Entity Framework 知道的内容。

于 2012-07-27T15:26:22.067 回答