Skip to content

Entity Framework UniqueAttribute [Mapping]

Victor Tomaili edited this page May 3, 2021 · 1 revision

(from the official guide)

[namespace: Serenity.Data.Mapping] - [assembly: Serenity.Data]

When a field has this flag, its value is checked against existing values in database to be unique.

You can turn on this flag with Unique attribute and determine if this constraint should be checked on service leve (before the check in database level to avoid cryptic constraint errors).

public sealed class UserRow : LoggingRow, IIdRow, INameRow, IIsActiveRow
{
   [Unique]
   public String Username
   {
      get { return Fields.Username[this]; }
      set { Fields.Username[this] = value; }
   }

See also:

Clone this wiki locally