0

I have two properties (First Name & Last Name) that I want both to be unique so the Full Name is Unique in database, so I searched here for a solution and found this

Unique multiple column in EF6 codefirst

and I applied It

    [Required]
    [Index("IX_fullname", 1, IsUnique = true)]
    public string f_name { get; set; }

    [Required]
    [Index("IX_fullname", 2, IsUnique = true)]
    public string l_name { get; set; }

but it did not work at all.

The link provided of the solution is actually the same solution I provided the link of, and actually it did not work, I can do what I want with JSON and I did that with code but I can't handle it to show the message after leaving the text box immediately like "this value is required".

Ahmad Adel
  • 136
  • 2
  • 11
  • You're asking too much in one question. You should have stopped after the first problem that you insufficiently describe by "but it did not work at all". *How* did it not work? – Gert Arnold Sep 16 '17 at 20:25
  • I just tried to solve it , I did not want my question to be marked as a duplicate, The problem is one after all , Multi-Column Uniqueness in my model. – Ahmad Adel Sep 16 '17 at 20:31
  • Anyway I will do as you said and remove unnecessary additions, thanks – Ahmad Adel Sep 16 '17 at 20:36
  • Possible duplicate of [Setting unique Constraint with fluent API?](https://stackoverflow.com/questions/21573550/setting-unique-constraint-with-fluent-api) – Ian Gesner Sep 17 '17 at 00:00
  • Or: https://stackoverflow.com/q/7590883/861716 – Gert Arnold Sep 17 '17 at 18:29

1 Answers1

0

Look at this:

Setting unique Constraint with fluent API?

It appears you also need to add a StringLength attribute to use this annotation.

Ian Gesner
  • 84
  • 3
  • The link provided of the solution is actually the same solution I provided the link of, and actually it did not work, I can do what I want with JSON and I did that with code but I can't handle it to show the message after leaving the text box immediately like "this value is required". – Ahmad Adel Sep 17 '17 at 00:41