Linq update RRS feed

  • Question

  • hi,

    I'm creating a repository to do some CRUD functions on the DB. This all with some handcoded Linq2sql objects. the CRD functions all work great, but when i try to update it seems to fail.

    When i use "table.Attach(entity, true);" it gives me a: "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."

    Therefore i came in the whole detach discussion. Here i'm trying to serialize and deserialize to use a option that the net gave me. but when i serialize is gives me an error on a null vallue of the object. The type of that object is a entitySet, an association i made to another object.

    I'm only trying to update the object i'm working with which hasn't initialized the associations. in what way i can accomplisch to make a real update?

    My serialization/deserialization function:

                DataContractSerializer dcs = new DataContractSerializer(entiteit.GetType());
                if (entiteit == null)
                    return null;
                StringBuilder sb = new StringBuilder();
                XmlWriter xmlw = XmlWriter.Create(sb);
                dcs.WriteObject(xmlw, entiteit);
                string serialized = sb.ToString();
                object entityTarget;
                StringReader sr = new StringReader(serialized);
                XmlTextReader xmltr = new XmlTextReader(sr);
                entityTarget = (object)dcs.ReadObject(xmltr);
                return (T)entityTarget;



    • Moved by liurong luo Monday, April 12, 2010 7:09 AM move to the right forum. (From:Visual C# General)
    Tuesday, April 6, 2010 10:42 AM