Note that there are some explanatory texts on larger screens.

plurals
  1. POLINQ to SQL Attaching collection of object from XML file Database
    primarykey
    data
    text
    <p>I am developing an HRM application to import and export xml data from database. The application receives exported xml data for the employee entry. I imported the xml file using linq to xml, where I converted the xml into respective objects. Then I want to attach (update) the employee objects.</p> <p>I tried to use</p> <pre><code>//linqoper class for importing xml data and converts into IEnumerable employees object. var emp = linqoper.importxml(filename.xml); Using (EmployeedataContext db = new EmployeedatContext){ db.attachAllonSubmit(emp); db.submitchange(); } </code></pre> <p>But I got error <code>“An entity can only be attached as modified without original state if it declares as version member or doesn't have an update check policy”</code>.</p> <p>I have also an option to retrieve each employee, and assign value to the new employee from xml data using this format.</p> <pre><code>//import IEnumerable of Employee objects var employees = = linqoper.importxml(filename.xml) using(Employeedatacontext db = new Employeedatacontext){ foreach(var empobj in employees) { Employee emp = db.Employee.where(m=&gt;m.id==empobj.Id); emp.FirstName=empobj.FirstName; emp.BirthDate=empobj.BirthDate; //….continue } db.submitChanges(); } </code></pre> <p>But the problem with the above is I have to iterate through the whole employee objects, which is very tiresome. So is there any other way, I could attach (update) the employee entity in the database using LINQ to SQL.</p> <p>I have seen some similar links on SO, but none of them seems to help.</p> <p><a href="https://stackoverflow.com/questions/898267/linq-to-sql-attach-refresh-entity-object/%22https://stackoverflow.com/questions/898267/linq-to-sql-attach-refresh-entity-object%22">https://stackoverflow.com/questions/898267/linq-to-sql-attach-refresh-entity-object</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload