Domanda

I'm using Entity Framework, model first, self-tracking entities with Npgsql provider (VS2010 - .NET 4 target).

I'm trying to track optimistic concurrency exceptions, but my problem is that as soon as a column in the entity is marked as fixed, an OptimisticConcurrencyException is raised, even if the affected rows > 0.

After some digging exposed here, I would like to know why Entity Framework is issuing the update command through dbCommand.ExecuteReader(CommandBehavior.SequentialAccess) followed by a dbDataReader.Read() instead of dbCommand.ExecuteNonQuery() when the command text is a simple update statement ?

UPDATE "schema"."table" 
SET "bool_column" = FALSE 
WHERE ("id" = 7526) AND ("xmin" = 1249804)

Thanks.

È stato utile?

Soluzione

The underlying provider should issue a SELECT statement right after an INSERT or UPDATE statement if there are any computed columns (StoreGeneratedPattern = "Computed" or "Identity") to retrieve.

Npgsql currently support only SERIAL during an INSERT operation. It does not support computed column retrieval during an UPDATE operation. The consumer should call Refresh(RefreshMode.StoreWins, entity) to get values from the datasource.

This implies that Optimistic Concurrency is not supported in the current version of the Npgsql provider.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top