0

I use the model which inherits IdentityUser.

public class User : IdentityUser
{
[TimeStamp]
public byte[] RowVersion {get;set;}
}

My question is: SecurityStamp in table AspNetUsers is the same like added RowVersion. I cannot add this property, because it shows me problem with concurrency check in subtypes.

maciejka
  • 818
  • 2
  • 17
  • 42

1 Answers1

1

SecurityStamp in table AspNetUsers is not exactly the same with RowVersion though the purpose is the same, to handle concurrency.

You may refer to this answer.

The security stamp can be anything you want. It is often mistaken to be a timestamp, but it is not. It will be overriden by ASP.NET Identity if something changes on the user entity. If you're working on the context directly the best way would to generate a new Guid and use it as the stamp.

Anyways, [Timestamp] attribute doesn't work for inheriting classes. It should be added on the base class instead. But for your case, it is not possible since you cannot add this directly on IdentityUser.

There is no point adding this on your User class because SecurityStamp already exists for the same purpose. Try using it on your other entities instead.

jegtugado
  • 5,081
  • 1
  • 12
  • 35
  • This is also how I treat the SecurityStamp on IdentityUser. I have a base class that all my other models inherit from. The base class contains a [Timestamp] RowVersion. However, I do not inherit my User model as it's already inheriting from IdentityUser which contains the SecurityStamp. – defect833 Sep 21 '17 at 03:53
  • Well, I am pointing out that adding the `Timestamp` on your `User` class won't work for the reason that it already inherits from `IdentityUser`. You won't be able to make your `RowVersion` work. – jegtugado Sep 21 '17 at 05:33
  • So method UserManager.UpdateSecurityStamp(userId) is enough to update SecurityStamp when some data in User has been changed? – maciejka Sep 21 '17 at 06:05
  • 1
    @maciejka please see https://stackoverflow.com/a/19505060/6138713 for a clearer purpose of `SecurityStamp`. – jegtugado Sep 21 '17 at 08:04