Note that there are some explanatory texts on larger screens.

plurals
  1. PODbContext/ObjectDataSource Update Issue
    primarykey
    data
    text
    <p>I have a <code>ObjectDataSource</code> Which Calls business layer methods to update EF and save. I have this weird problem. Following is ODS markup:</p> <pre><code>&lt;asp:ObjectDataSource ID="odsDeviceForm" runat="server" ypeName="Spectre.BLL..DeviceManager" DataObjectTypeName="Model.Device" SelectMethod="GetById" InsertMethod="Insert" oninserting="OnItemInserting" UpdateMethod="UpdateEx" oninserted="OnItemInserted" onupdated="OnItemUpdated" onupdating="OnItemUpdating" onobjectcreated="OnOdsObjectCreated" onselected="OnOdsItemSelected" ConflictDetection="CompareAllValues" OldValuesParameterFormatString="orig{0}" &gt; &lt;SelectParameters&gt; &lt;asp:SessionParameter Name="primaryKey" SessionField="SelectedDeviceId" Type="Int32" /&gt; &lt;/SelectParameters&gt; </code></pre> <p></p> <p>Following is BLL and repositoryCode: BLL:</p> <pre><code>public void UpdateEx(T entity, T origentity) { try { repository.Update(origentity, entity); repository.Save(); } catch (Exception) { throw; } } </code></pre> <p>Repository:</p> <pre><code>public void Update(T orig, T newEntity) { myContext.Entry&lt;T&gt;(newEntity).CurrentValues.SetValues(newEntity); } </code></pre> <p>When This code runs I get an exception:</p> <blockquote> <p>Member 'CurrentValues' cannot be called for the entity of type 'Device' because the entity does not exist in the context. To add an entity to the context call the Add or Attach method of DbSet.</p> </blockquote> <p>But if I do dbset.attach then I get exception that the entity already exists.</p> <p>I have no idea what can I do, seems like a circular problem to me. I have gone half bald pulling my hair over this. Please help.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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