none
EntityFramework 4 - Adding a object without Identity column throws OptimisticConcurrencyException RRS feed

  • General discussion

  • Hi,

     I have a database first approach, using EF4 on Sybase.

    SSDL

        <EntityType Name="tq_qmt_logger">
        <Key>
        <PropertyRef Name="qmt_id" />
        </Key>
        <Property Name="qmt_id" Type="bigint" Nullable="false" StoreGeneratedPattern="Identity"  />
        <Property Name="client_id" Type="varchar" Nullable="false" MaxLength="100" />
        <Property Name="logged_date" Type="datetime" Nullable="false" />

    CSDL

    I have corresponding CSDL with annotation:StoreGeneratedPattern="Identity"

    Now my source code is,

     
       tq_qmt_logger qmtLogger = new tq_qmt_logger();
       qmtLogger.client_id = machineID;
       qmtLogger.logged_date = DateTime.Now;
    
       //qmtlogger.qmt id is omitted because it is
       // generated by a sequence in the DB.
    
       context.tq_qmt_logger.AddObject(qmtLogger);
       context.savechanges()


    SaveChanges throws OptimisticConcurrencyException with error Store update, insert, or delete statement affected an unexpected number of rows (0). My guess is, EF passes 0 to my qmt_id (identity) column, which is getting rejected. Can someone guide how to fix this?
    Friday, October 9, 2015 1:22 AM

All replies

  • Hello There,

    Please refer below link

    http://stackoverflow.com/questions/20044828/store-update-insert-or-delete-statement-affected-an-unexpected-number-of-rows

    Cheers

    Wednesday, October 14, 2015 11:36 AM