Unique constraint entity framework

c# entity-framework entity-framework-6 visual-studio-2013

Question

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

1
1
1/14/2015 11:11:52 PM

Popular Answer

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; }
1
5/23/2017 12:10:23 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow