Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unique field in class model .net core

//single index
[Index("IX_First", IsUnique = true)]
public int FirstColumn { get; set; }

// composite index
[Index("IX_FirstAndSecond", 1, IsUnique = true)]
public int FirstColumn { get; set; }

[Index("IX_FirstAndSecond", 2, IsUnique = true)]
public int SecondColumn { get; set; }

//using bulder

protected override void OnModelCreating(ModelBuilder builder)
{
    builder.Entity<User>()
        .HasIndex(u => u.Email)
        .IsUnique();
}

public class User
{
   public int UserId{get;set;}
   [StringLength(450)]
   [Index(IsUnique=true)]
   public string UserName{get;set;}
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: decimal operator in Convert.toDouble() C# 
Csharp :: c# open access database mdb 
Csharp :: dinktopdf page break 
Csharp :: how to query items with any id in a list of ids linq c# 
Csharp :: regular expression alphanumeric dash space c# 
Csharp :: Make UI/Canvas look at Camera always. 
Csharp :: unity draw waypoints path 
Csharp :: how to access path position variable in unity 
Csharp :: webclient c# example post 
Csharp :: how to detect ajax request in asp.net core 
Csharp :: c# out parameter 
Csharp :: extension method in c# 
Csharp :: unity datetime to string 
Csharp :: sustituir un caracter de un string c# 
Csharp :: how to round to nearest number in array c# 
Csharp :: rename join table ef core 
Csharp :: drawing default serializedproperty unity 
Csharp :: unity change fixed timestep in code 
Csharp :: unity vector3 initialization 
Csharp :: asp net core dependency injection factory with parameters 
Csharp :: c# decimal to fixed 2 
Csharp :: create list of strings from field of list of object c# 
Csharp :: oncollisionenter2d 
Csharp :: dotnet add package 
Csharp :: C# Async Function without await 
Csharp :: datetimeoffset to datetime 
Csharp :: get xml from url 
Csharp :: triangle 
Csharp :: inheritance 
Csharp :: muovere un elemento in c# 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =