Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7175217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:14:21+00:00 2026-05-28T16:14:21+00:00

I have a CF class: public class A { [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id

  • 0

I have a CF class:

public class A
{
  [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  public int Id {get;set;}
  [Required]
  public string Name {get;set;}
  public string LoweredName {get;set;}
  [Timestamp]
  public byte[] RowVersion {get;set;}
}

In the database i have a trigger:

CREATE TRIGGER IOI_LoweredName
   ON  Abc
   INSTEAD OF INSERT
AS; 
BEGIN;
    SET NOCOUNT ON;

    INSERT INTO Abc(Name, LoweredName) SELECT Name, LOWER(Name) FROM inserted
END;

Now if i try to insert a record:

dc.Names.Add(new A { Name = "Test" });
dc.SaveChanges();

I get the following error:

Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.

Any ideas how to get around this?
All my classes inherit from a base class that has the RowVersion (Timestamp) column. Can’t i use such a simple trigger with EF when using concurrency on a timestamp field ?

Updated

There is a primary key (also added it to the example above).

Update 2

This is from the SQL Profiler:

declare @0 nvarchar(100)
set @0=N'Test'
insert [dbo].[abc]([Name], [LoweredCompanyName]) values (@0, null)
select [Id], [RowVersion] from [dbo].[Abc] where @@ROWCOUNT > 0 and [Id] = scope_identity()

Problem is that the select doesn’t return anything.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:14:22+00:00Added an answer on May 28, 2026 at 4:14 pm

    That entity doesn’t have primary key. EF will not like it.

    To fix the current error try to add this at the end of your trigger:

    SELECT @@ROWCOUNT
    

    If you change your code to support auto generated PK, you will use this instead:

    SELECT SCOPE_IDENTITY()
    

    I’m not sure if this will actually work with instead of trigger but it was necessary when mapping stored procedures to modification operations in EDMX.

    Currently it is possible that this operation will be executed by EF directly but it will not count records created or modified by trigger because trigger executes in different scope – that can be a big problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an abstract superclass DataContent: public abstract class DataContent { [Key(), DatabaseGenerated(DatabaseGeneratedOption.Identity)] public
I have a following POCO class public class Account { [Key,DatabaseGenerated(DatabaseGenerationOption.Identity)] public string AccountId
I have class like this: public class object { [Key] int number; String mystring;
I have a domain class like public class Category { [Key] public string IdCategory
I have a class with an indexer property, with a string key: public class
So, I have this class: public class Product { private String name, id, info
I have a class like the following: public class DropDownControl<T, Key, Value> : BaseControl
I have class Fred { public: void inspect() const {}; void modify(){}; }; int
I have following class public class ButtonChange { private int _buttonState; public void SetButtonState(int
I have this class: public MyClass { public void initialize(Collection<String> data) { this.data =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.