1

I'm using MS SQL Server 2012 + the Entity Framework 6.1.1. I have created a model using the designer. Now, I would like to add a unique to an attribute. How can I achieve this using the designer / keep the model generation?

Edit: I do the model first approach

Thank you

mitchkman
  • 6,201
  • 8
  • 39
  • 67

1 Answers1

1

Read this! It should help you in the right direction...

The idea is to use code like this:

CreateIndex("dbo.Users","Username",true);

Which is a EF method. I don't think it's possible in the designer then...

EDIT

Found this post that states that unique constraints are possible (not in the designer, but in code) like this:

[Index(IsUnique = true)]
public string EmailAddress { get; set; }
Community
  • 1
  • 1
Youp Bernoulli
  • 5,303
  • 5
  • 39
  • 59