Note that there are some explanatory texts on larger screens.

plurals
  1. POEF 4.0 Entity does not pick up new values after insert (select entity after insert)
    primarykey
    data
    text
    <p>I am using Entity Framework 4.0 POCO entity I have mapped custom stored procedure on insert PROCEDURE [dbo].[usp_MyTable_Insert] ( @Value1 char(1), @Value2 varchar(5), @Value3 varchar(20) .... ) AS BEGIN TRANSACTION INSERT INTO "dbo"."MyTable" ( "Value1", "Value2", "Value3" ) VALUES ( @Value1, @Value2, @Value3 )</p> <p>DECLARE @Id int --Get the latest Id. SET @Id = ( SELECT CAST(@@IDENTITY AS INT) )</p> <p>--update the table with the some values UPDATE "dbo"."MyTable" SET Value3 = ( SELECT SomeTableColumn FROM SomeTable WHERE Something = Something ) WHERE [Id] = @Id </p> <p>COMMIT TRANSACTION</p> <p>SELECT @Id AS "Id"</p> <p>END</p> <p>It is inserting entity into database and then updating some of the columns in database then returning identity. All pretty simple.</p> <p>public int InsertRecord(RecEntity recEntity) { context.AddObject("RecEntities", recEntity);</p> <pre><code> context.SaveChanges(); return recEntity.Id; } </code></pre> <p>Method insert working well. Then i need to update current entity with values which stored procedure inserted. I have method in my repository to retrieve data </p> <p>public RecEntity SingleRecEntity(Expression> where) { return context.RecEntities.Single(where); } When i am calling this method values values inserted by stored procedure doesn't come to entity.</p> <p>id = repository.InsertRecord(recEntity); recEntity = repository.SingleBrokerPreRegistration(x => x.Id == id); // new values didnt come here from database</p> <p>I run the query generated by entity framework in query analyzer, it is returning all up to date values. But fore some reason datacontext don't want to update this entity.</p> <p>Probably there is should be some ways to change this. May be some one may explain this behaviour. Need 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.
 

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