Question

Nous utilisons Entity Framework 4.1 Code du premier.

Nous avons entité utilisateur avec jeu de clé primaire à UserId et le besoin UserLogin d'être unique. Comment peut-il être fait?

Était-ce utile?

La solution

Entity Framework does not support Unique constraints. You can create them using a SQL Query to generate unique constrains when initializing the database. Write your custom initializer for the model and execute SQL command to generate constrain.

Edit

Now (EF 6.1 onwards )you can easily have unique constrains ,

[Index("UserLoginIndex", IsUnique = True)]
public string UserLogin { get; set; }

Autres conseils

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top